Image Alignment Code in MATLAB

조회 수: 72 (최근 30일)
Joe
Joe 2013년 10월 11일
댓글: Sherwin Theophilus 2022년 5월 16일
I've been trying everything I can find, but I can't seem to come up with a code that aligns my images very well. I have been using the pressure taps on the image to align the images manually, so using those again would be great. I've gotten to within a few pixels, but I need it to be with at least pixel accuracy, ideally subpixel accuracy. Here's an example of one of the codes that seems to do semi well.
img1 = 255-mean(imread('01_wing.png'),3);
img2 = 255-mean(imread('02_wing.png'),3);
c = normxcorr2(img2,img1);
[y x] = find(c==max(c(:)));
y = y-size(img2,1);
x = x-size(img2,2);
TFORM = maketform('affine',[1 0 x;0 1 y; 0 0 1]');
NEWimg2 = imtransform(img2,TFORM,'xdata',[1 size(img1,2)],'ydata',[1 size(img1,1)]);
I've attached the wing images in a zip file. The image below is an example of the pressure taps not aligning correctly.
What should I do differently?
  댓글 수: 1
Joe
Joe 2013년 10월 25일
I found the function cpcorr() very useful to fine-tune control points I had selected elsewhere before using Matt J's solution. Another solution I found was to takemy control points I found using corners(), refine them with cpcorr(), and finally plug them into fitgeotrans(). Hopefully this helps someone as much as it helped me!

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2013년 10월 15일
편집: Matt J 2013년 10월 15일
If you can extract the coordinates of the pressure taps in each image e.g., using regionprops(...,'WeightedCentroid'), then you could try using
to find the transformation that aligns them.
Even better would be if you already knew the 2D coordinates of the pressure taps with high accuracy in some prior template image. Then you could register both '01_wing.png' and '02_wing.png' to that.
  댓글 수: 11
Matt J
Matt J 2022년 5월 16일
If you have the Image Processing Toolbox, you could use imwarp. However, if you have the toolbox, you needn't have used absor. You could have used fitgeotrans from the very beginning. See also,
Sherwin Theophilus
Sherwin Theophilus 2022년 5월 16일
Thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2013년 10월 11일
Why not use imregister()? It's in the Image Processing Toolbox.
  댓글 수: 8
Joe
Joe 2013년 10월 15일
Sure, I'll post it when I get back to my school computer tonight. Thanks for all of your help by the way! I've been reading your post history in other image alignment questions too!
Matt J
Matt J 2013년 10월 15일
편집: Matt J 2013년 10월 15일
I can imagine imregister() having difficulty if the pressure taps in image A do not have any initial overlap with the taps in image B. The initial gradient of the registration metric will be zero in that case and the algorithm won't be able to move.
With normxcorr2, you would hopefully be able to obtain that initial overlap, but since the taps are so small, it is unclear.

댓글을 달려면 로그인하십시오.


Eric
Eric 2013년 10월 15일
Here's what works well for me:
2. Register the gradients of the images, not the images themselves.
Here's my code:
%Load data
im1Orig = double(imread('01_wing.png'));
im2Orig = double(imread('02_wing.png'));
%Calculate gradients
im1 = imgradient(im1Orig);
im2 = imgradient(im2Orig);
%Get registration values
[output, Greg] = dftregistration(fft2(im1),fft2(im2),50);
%Translate image
imOut = TranslateImage(im2, output(3), output(4),'method','Fourier');
I get a row shift of -0.36 pixels and a column shift of +3.06 pixels. My function TranslateImage is basically:
img_out = TranslateImage(img_in, rowshift, colshift)
%%Create frequency space sampling vectors
[numrows, numcols] = size(img_in);
[n,m] = meshgrid(-fix(numcols/2):fix((numcols-1)/2),-fix(numrows/2):fix((numrows-1)/2));
m = m/numrows;
n = n/numcols;
%%Perform translation in the Fourier domain
img_fft = fftshift(fft2(ifftshift(double(img_in))));%Cast the input image to a double
shiftOtf = exp(-1i*2*pi*m*rowshift) .* exp(-1i*2*pi*n*colshift);
img_fft_trans = img_fft .* shiftOtf;
img_out = real(fftshift(ifft2(ifftshift(img_fft_trans))));
return
end
For monomodal image registration with pure translation, there are many algorithms that work better than imregister().
Good luck,
Eric
  댓글 수: 1
Eric
Eric 2013년 10월 15일
I should point out that pure translation doesn't appear to be totally valid for these images, but it's close. Some of the features line up very well, while others are still off by a pixel.
-Eric

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by