def cross_corr(img1,img2,mask=None):
'''Compute the autocorrelation of two images.
Right now does not take mask into account.
todo: take mask into account (requires extra calculations)
input:
img1: first image
img2: second image
mask: a mask array
output:
the autocorrelation of the two images (same shape as the correlated images)
'''
#if(mask is not None):
# img1 *= mask
# img2 *= mask
#img1_mean = np.mean( img1.flat )
#img2_mean = np.mean( img2.flat )
# imgc = fftshift( ifft2(
# fft2(img1/img1_mean -1.0 )*np.conj(fft2( img2/img2_mean -1.0 ))).real )
#imgc = fftshift( ifft2(
# fft2( img1/img1_mean )*np.conj(fft2( img2/img2_mean ))).real )
imgc = fftshift( ifft2(
fft2( img1 )*np.conj(fft2( img2 ))).real )
#imgc /= (img1.shape[0]*img1.shape[1])**2
if(mask is not None):
maskc = cross_corr(mask,mask)
imgc /= np.maximum( 1, maskc )
return imgc
Spatial_Correlation_Function.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录