def find_subpixel_peak_position(corr, subpixel_method='gaussian'):
    """
    Find subpixel approximation of the correlation peak.
    
    This function returns a subpixels approximation of the correlation
    peak by using one of the several methods available. If requested, 
    the function also returns the signal to noise ratio level evaluated 
    from the correlation map.
    
    Parameters
    ----------
    corr : np.ndarray
        the correlation map.
        
    subpixel_method : string
         one of the following methods to estimate subpixel location of the peak: 
         'centroid' [replaces default if correlation map is negative], 
         'gaussian' [default if correlation map is positive], 
         'parabolic'.
         
    Returns
    -------
    subp_peak_position : two elements tuple
        the fractional row and column indices for the sub-pixel
        approximation of the correlation peak.

    Original code from openPIV pyprocess

    """
    # initialization
    default_peak_position = (corr.shape[0]/2,corr.shape[1]/2)

    # the peak locations
    peak1_i, peak1_j, dummy = find_first_peak(corr)
    
    try:
        # the peak and its neighbours: left, right, down, up
        c = corr[peak1_i, peak1_j]
        cl = corr[peak1_i-1, peak1_j]
        cr = corr[peak1_i+1, peak1_j]
        cd = corr[peak1_i, peak1_j-1] 
        cu = corr[peak1_i, peak1_j+1]
        
        # gaussian fit
        if np.any(np.array([c,cl,cr,cd,cu]) < 0) and subpixel_method == 'gaussian':
            subpixel_method = 'centroid'
        
        try: 
            if subpixel_method == 'centroid':
                subp_peak_position = (((peak1_i-1)*cl+peak1_i*c+(peak1_i+1)*cr)/(cl+c+cr),
                                    ((peak1_j-1)*cd+peak1_j*c+(peak1_j+1)*cu)/(cd+c+cu))
        
            elif subpixel_method == 'gaussian':
                subp_peak_position = (peak1_i + ((np.log(cl)-np.log(cr))/(2*np.log(cl) - 4*np.log(c) + 2*np.log(cr))),
                                    peak1_j + ((np.log(cd)-np.log(cu))/( 2*np.log(cd) - 4*np.log(c) + 2*np.log(cu)))) 
        
            elif subpixel_method == 'parabolic':
                subp_peak_position = (peak1_i +  (cl-cr)/(2*cl-4*c+2*cr),
                                        peak1_j +  (cd-cu)/(2*cd-4*c+2*cu)) 
    
        except: 
            subp_peak_position = default_peak_position
            
    except IndexError:
            subp_peak_position = default_peak_position
            
    return subp_peak_position[0], subp_peak_position[1]
def find_subpixel_peak_position ( corr , subpixel_method = 'gaussian' ) : default_peak_position = ( corr . shape [ 0 ] / 2 , corr . shape [ 1 ] / 2 ) peak1_i , peak1_j , dummy = find_first_peak ( corr ) try : c = corr [ peak1_i , peak1_j ] cl = corr [ peak1_i - 1 , peak1_j ] cr = corr [ peak1_i + 1 , peak1_j ] cd = corr [ peak1_i , peak1_j - 1 ] cu = corr [ peak1_i , peak1_j + 1 ] if np . any ( np . array ( [ c , cl , cr , cd , cu ] ) < 0 ) and subpixel_method == 'gaussian' : subpixel_method = 'centroid' try : if subpixel_method == 'centroid' : subp_peak_position = ( ( ( peak1_i - 1 ) * cl + peak1_i * c + ( peak1_i + 1 ) * cr ) / ( cl + c + cr ) , ( ( peak1_j - 1 ) * cd + peak1_j * c + ( peak1_j + 1 ) * cu ) / ( cd + c + cu ) ) elif subpixel_method == 'gaussian' : subp_peak_position = ( peak1_i + ( ( np . log ( cl ) - np . log ( cr ) ) / ( 2 * np . log ( cl ) - 4 * np . log ( c ) + 2 * np . log ( cr ) ) ) , peak1_j + ( ( np . log ( cd ) - np . log ( cu ) ) / ( 2 * np . log ( cd ) - 4 * np . log ( c ) + 2 * np . log ( cu ) ) ) ) elif subpixel_method == 'parabolic' : subp_peak_position = ( peak1_i + ( cl - cr ) / ( 2 * cl - 4 * c + 2 * cr ) , peak1_j + ( cd - cu ) / ( 2 * cd - 4 * c + 2 * cu ) ) except : subp_peak_position = default_peak_position except IndexError : subp_peak_position = default_peak_position return subp_peak_position [ 0 ] , subp_peak_position [ 1 ]
Find subpixel approximation of the correlation peak.
    
    This function returns a subpixels approximation of the correlation
    peak by using one of the several methods available. If requested, 
    the function also returns the signal to noise ratio level evaluated 
    from the correlation map.
    
    Parameters
    ----------
    corr : np.ndarray
        the correlation map.
        
    subpixel_method : string
         one of the following methods to estimate subpixel location of the peak: 
         'centroid' [replaces default if correlation map is negative], 
         'gaussian' [default if correlation map is positive], 
         'parabolic'.
         
    Returns
    -------
    subp_peak_position : two elements tuple
        the fractional row and column indices for the sub-pixel
        approximation of the correlation peak.

    Original code from openPIV pyprocess