% IMSHIFT_FFT will apply shift with subpixel accuracy that can be different for each frame. % % img = imshift_fft(img, x,y, apply_fft = true, weights = []) % % Inputs: % **img - input image stack, can be complex valued % **x, y - shifts in number of pixels % **apply_fft , if false, then images will be assumed to be in fourier space % **weights - 0 faster img = utils.imshift_fft_ax(img, y,1, apply_fft); elseif all(y==0) img = utils.imshift_fft_ax(img, x,2, apply_fft); else %% 2D FFT SHIFTING real_img = isreal(img); Np = size(img); if apply_fft img = math.fft2_partial(img); end xgrid = ifftshift(-fix(Np(2)/2):ceil(Np(2)/2)-1)/Np(2); X = reshape((x(:)*xgrid)',1,Np(2),[]); X = exp((-2i*pi)*X); img = bsxfun(@times, img,X); ygrid = ifftshift(-fix(Np(1)/2):ceil(Np(1)/2)-1)/Np(1); Y = reshape((y(:)*ygrid)',Np(1),1,[]); Y = exp((-2i*pi)*Y); img = bsxfun(@times, img,Y); if apply_fft img = math.ifft2_partial(img); end if real_img img = real(img); end end if ~isempty(weights) && ~isscalar(weights) && apply_fft weights = utils.imshift_fft(weights, x,y); %% weights needs to be shifted as well img = img ./ weights; end end