def lanczosSubPixKernel( subPixShift, kernelShape=3, lobes=None ):
"""
Generate a kernel suitable for ni.convolve to subpixally shift an image.
"""
kernelShape = np.array( [kernelShape], dtype='int' )
if kernelShape.ndim == 1: # make it 2-D
kernelShape = np.array( [kernelShape[0], kernelShape[0]], dtype='int' )
if lobes is None:
lobes = (kernelShape[0]+1)/2
x_range = np.arange(-kernelShape[1]/2,kernelShape[1]/2)+1.0-subPixShift[1]
x_range = ( 2.0 / kernelShape[1] ) * x_range
y_range = np.arange(-kernelShape[1]/2,kernelShape[0]/2)+1.0-subPixShift[0]
y_range = ( 2.0 /kernelShape[0] ) * y_range
[xmesh,ymesh] = np.meshgrid( x_range, y_range )
lanczos_filt = np.sinc(xmesh * lobes) * np.sinc(xmesh) * np.sinc(ymesh * lobes) * np.sinc(ymesh)
lanczos_filt = lanczos_filt / np.sum(lanczos_filt) # Normalize filter output
return lanczos_filt
评论列表
文章目录