필터 지우기
필터 지우기

How can I align an image according to another image?

조회 수: 3 (최근 30일)
Vic
Vic 2013년 1월 27일
I am trying to align an image according to a base image and according to the position of 2 circles on the left of each page.
The link for unregistered image: http://tinypic.com/view.php?pic=2zsbmuu&s=6
The code I have so far is listed below but the only thing I have a problem with is how to use imtransfrom function to register the image.
  댓글 수: 1
Vic
Vic 2013년 1월 27일
I1 = imread('C:\Users\Victoras\Desktop\answertest.bmp');
J1= imread('C:\Users\Victoras\Desktop\studenttest.bmp');
I2= rgb2gray(I1); %convert colour images to grayscale
J2= rgb2gray(J1);
BWI = im2bw(I2);% convert grayscale images to binary
BWJ = im2bw(J2);
IMI = imcomplement(BWI); % invert colours, black to white and white to black
IMJ = imcomplement(BWJ);
%imshow(IMI);
%imshow(IMJ);
BWIremove = bwareaopen(IMI, 5000); % remove objects less that 4500 pixels
BWJremove = bwareaopen(IMJ, 5000);
%imshow(BWIremove);
%imshow(BWJremove);
[LI, numI] = bwlabel(BWIremove);
[LJ, numJ] = bwlabel(BWJremove);
centroidsI = regionprops(LI,'Centroid');
centroidsJ = regionprops(LJ,'Centroid');
% Create a transformation structure for an affine % transformation.
t_concord = cp2tform(centroidsI,centroidsJ,'affine');
% Get the width and height of the orthophoto and perform % the transformation.
info = imfinfo(I1);
registered = imtransform(IMJ,t_concord,'XData',[1 info.Width], 'YData',[1 info.Height]);
figure, imshow(registered)

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

채택된 답변

Image Analyst
Image Analyst 2013년 1월 27일
Have you tried imregister()? It will condense all that code down into a single line of code. Go ahead, make it easy on yourself.
  댓글 수: 11
Image Analyst
Image Analyst 2013년 1월 27일
That said, if you could figure out a transform, tformfwd() would probably be faster than calling imregister() three times.
Matt J
Matt J 2013년 1월 27일
편집: Matt J 2013년 1월 27일
Seems like a fluke to me. What if all the 'A' answers had been filled out in the first image and all the 'D' Answers had been filled out in the second? The alignment of the blue channels would have been heavily inconsistent with the other channels.

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

추가 답변 (1개)

Matt J
Matt J 2013년 1월 27일
편집: Matt J 2013년 1월 27일
Here's a modification of the original approach using ABSOR, available here
[LI, numI] = bwlabel( imfill(BWIremove,'holes') );
[LJ, numJ] = bwlabel( imfill(BWJremove,'holes') );
centroidsI = regionprops(LI,'Centroid');
centroidsJ = regionprops(LJ,'Centroid');
% Create a transformation structure for an affine % transformation.
cI=vertcat(centroidsI.Centroid);
cJ=vertcat(centroidsJ.Centroid);
S=absor(cJ.', cI.');
t_concord=maketform('affine', S.M(1:2,:).');
registered = imtransform(IMJ,t_concord,....);
Because you're only using 2 landmarks to perform the registration, the alignment will probably not be as perfect as with imregister, although as I've said, I have my doubts about how well imregister would work across a larger population of questionnaires.
There are things you could do to improve the tilt angle estimate though, like find more landmarks, or use regionprops(...,'Orientation') on the answer boxes.

카테고리

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