def lanczosIndexedShift( params ):
""" lanczosIndexedShift( params )
params = (index, imageStack, translations, kernelShape=3, lobes=None)
imageStack = input 3D numpy array
translations = [y,x] shift, recommened not to exceed 1.0, should be float
Random values of kernelShape and lobes gives poor performance. Generally the
lobes has to increase with the kernelShape or you'll get a lowpass filter.
Generally lobes = (kernelShape+1)/2
kernelShape=3 and lobes=2 is a lanczos2 kernel, it has almost no-lowpass character
kernelShape=5 and lobes=3 is a lanczos3 kernel, it's the typical choice
Anything with lobes=1 is a low-pass filter, but next to no ringing artifacts
If you cheat and pass in rounded shifts only the roll will be performed, so this can be used to accelerate
roll as well in a parallel environment.
"""
if len( params ) == 3:
[index, imageStack, translations] = params
kernelShape = 3
lobes = None
elif len( params ) == 4:
[index, imageStack, translations, kernelShape] = params
lobes = None
elif len( params ) == 5:
[index, imageStack, translations, kernelShape, lobes] = params
integer_trans = np.round( translations[index,:] ).astype('int')
# Integer shift
imageStack[index,:,:] = np.roll( np.roll( imageStack[index,:,:],
integer_trans[0], axis=0 ),
integer_trans[1], axis=1 )
# Subpixel shift
remain_trans = np.remainder( translations[index,:], 1)
if not (np.isclose( remain_trans[0], 0.0) and np.isclose( remain_trans[1], 0.0) ):
kernel = lanczosSubPixKernel( remain_trans, kernelShape=kernelShape, lobes=lobes )
# RAM: I tried to use the out= keyword but it's perhaps not thread-safe.
imageStack[index,:,:] = scipy.ndimage.convolve( imageStack[index,:,:], kernel, mode='reflect' )
评论列表
文章目录