How to align two images which are only several pixels away in vertical direction?

조회 수: 4 (최근 30일)
Hi, Guys,
There are two images and they are several pixels away in the vertical (Y) direction. I want to align them automatically. My plan is to draw a line in the two images and calculate the Normalized cross-correlation, and find coordinates of peak. The idea is from Registering an Image Using Normalized Cross-Correlation . But I don't know how to find the offset between the two lines.
normxcorr2_2diff = normxcorr2(template_line, other_line);
[max_c, imax] = max(abs(normxcorr2_2diff(:)));
[ypeak, xpeak] = ind2sub(size(normxcorr2_2diff),imax(1));
In the above code, size(template_line) = 89, size(other_line)=176, size(normxcorr2_2diff)=264, ypeak=135. You can load template_line and other_line from the attached .mat file.So how can we find the offset from these results? If the offset can be determined, I can use imtranslate to move the line (image). Let's use template_line as the reference (fixed) line and want to move other_line to align with it.
So this is my thought. Otherwise, is there other easier or more direct approaches to do this? Since two images are away only several pixels in Y direction, is there a globe way (based on two entire images and then find the offset in Y direction) to align them? I also consider imregister . But haven't figure out how to use it in my case.
Thank you very much.

답변 (3개)

Image Analyst
Image Analyst 2014년 11월 9일
You want to use imregister() instead of normxcorr2(). There is an example in the help that you can easily adapt.
  댓글 수: 3
Image Analyst
Image Analyst 2018년 5월 4일
You can't do a regression if you have less than the number of points than the order. For example, you can't fit a parabola through 2 points can you? You need at least 3. Likewise you can't register a 3-by-3 image to another 3-by-3 image. Why are your images so small?
Stelios Fanourakis
Stelios Fanourakis 2018년 5월 5일
Sorry, it was a mistake of mine but now has fixed. Thank for responding

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


Alex Taylor
Alex Taylor 2014년 11월 11일
Also look at imregcorr. It uses phase correlation and is easier to use than imregister. I'd start there.
  댓글 수: 1
YZ
YZ 2014년 11월 11일
Thank you, Alex.
The difference in two image is subtle, probably only 1 or 2 pixels away along Y direction. I used the following codes:
fixed = img_alldyn(:,:,1);
moving = img_alldyn(:,:,2);
tformEstimate = imregcorr(moving,fixed, 'translation');
movingReg = imwarp(moving,tformEstimate);
figure;
subplot(1,3,1); imshow(fixed,[]); imcontrast;
subplot(1,3,2); imshow(moving,[]); imcontrast;
subplot(1,3,3); imshow(movingReg,[]); imcontrast;
As a result, tformEstimate.T = [1,0,0;0,1,0;0,0,1]. What does this mean?
Thank you.

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


martin hauhana
martin hauhana 2015년 10월 8일
How can I write a code to align NIR and RGB images

카테고리

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