How can I align an image according to another image?

3 次查看(过去 30 天)
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