In order to improve S/N ratio, microscopist uses several short acquisition time images, and then sum them up. So the drift correction is very important. Here is the demo of how to use Matlab do drift correction.
In the first, load an image, and using circshift function to shift the object in the image.
Then use fft cross correlation to compute the moving distance.
Finally, shift the object to the origial position.
Here is the testing code:
==
% Demo of drift correction
% 2018/11/15 by Renfong
im1= imread('cameraman.tif'); % reference image
[sy,sx]=size(im1);
% shift the object
im2=circshift(im1,[20,10]); % the object moved down 20 pixels and moved right 10 pixels.
figure(1);
subplot(121);imshow(im1);
subplot(122);imshow(im2);
% Using fft cross correlations to detect the moving distance[1]
fftim1=fft2(im1);
fftim2=fft2(im2);
cc=fftshift(ifft2(fftim1.*conj(fftim2)));
[shiftY,shiftX]=find(cc==max(cc(:)));
shiftY=shiftY-fix(sy/2)-1;
shiftX=shiftX-fix(sx/2)-1;
figure(2);
imshow(mat2gray(cc)); hold on;
plot(fix(sx/2),fix(sy/2),'r+'); hold off;
% show result
corrected_im2=circshift(im2,[shiftY,shiftX]);
figure(3);
subplot(121);imshow(im2);
subplot(122);imshow(corrected_im2);
==
Ref:
[1] doi: 10.1017/S1551929514000790
In the first, load an image, and using circshift function to shift the object in the image.
Then use fft cross correlation to compute the moving distance.
Finally, shift the object to the origial position.
Here is the testing code:
==
% Demo of drift correction
% 2018/11/15 by Renfong
im1= imread('cameraman.tif'); % reference image
[sy,sx]=size(im1);
% shift the object
im2=circshift(im1,[20,10]); % the object moved down 20 pixels and moved right 10 pixels.
figure(1);
subplot(121);imshow(im1);
subplot(122);imshow(im2);
% Using fft cross correlations to detect the moving distance[1]
fftim1=fft2(im1);
fftim2=fft2(im2);
cc=fftshift(ifft2(fftim1.*conj(fftim2)));
[shiftY,shiftX]=find(cc==max(cc(:)));
shiftY=shiftY-fix(sy/2)-1;
shiftX=shiftX-fix(sx/2)-1;
figure(2);
imshow(mat2gray(cc)); hold on;
plot(fix(sx/2),fix(sy/2),'r+'); hold off;
% show result
corrected_im2=circshift(im2,[shiftY,shiftX]);
figure(3);
subplot(121);imshow(im2);
subplot(122);imshow(corrected_im2);
==
Ref:
[1] doi: 10.1017/S1551929514000790
Comments
Post a Comment