how can i transform the image from irregular rectangle to rectangle and finding the exact corners of the resultant image

8 views (last 30 days)
hi..... I am new to matlab. my task is transformation of image from irregular rectangle form the rectangle and finding the corners of the resultant image. i am using imtransform command for transformation of image, i getting the rectangle. and also getting the corners of the resultant image, but the problem is the corners of the resultant rectangle is not exact values. i am using the resultant rectangle corners for finding the point in that rectangle. so please help me.. up to now my code and image is attached below ...
a=imread('c\image1.bmp'); % original image i.e irregular rectangle.
b=im2bw(a,0.2);
%%%finding corners of the orginal image%%
[y,x] = find(b);
[~,loc] = min(y+x);
C = [x(loc),y(loc)];
OTL=[x(loc),y(loc)] %%top left coordinates
[~,loc] = min(y-x);
C(2,:) = [x(loc),y(loc)];
OTR=[x(loc),y(loc)] %%top right coordinates
[~,loc] = max(y+x);
C(3,:) = [x(loc),y(loc)];
OBR=[x(loc),y(loc)] %%bottom right coordinates
[~,loc] = max(y-x);
C(4,:) = [x(loc),y(loc)];
OBL=[x(loc),y(loc)] %%bottom left coordinates
%%find the location of new corners%%
L = mean(C([1 4],1));
R = mean(C([2 3],1));
U = mean(C([1 2],2));
D = mean(C([3 4],2));
C2 = [L U; R U; R D; L D];
%%image transformation %%
T = cp2tform(C ,C2,'projective');
IT= imtransform(b,T,'XData',[1 size(a,2)],...
'YData',[1 size(a,1)]); % getting the same resolution of original image
find each of new corners
[y,x] = find(IT);
[~,loc] = min(y+x);
FC= [x(loc),y(loc)];
FTL=[x(loc),y(loc)]
[~,loc] = min(y-x);
FC(2,:) = [x(loc),y(loc)];
FTR=[x(loc),y(loc)]
[~,loc] = max(y+x);
FC(3,:) = [x(loc),y(loc)];
FBR=[x(loc),y(loc)]
[~,loc] = max(y-x);
FC(4,:) = [x(loc),y(loc)];
FBL=[x(loc),y(loc)]
and my results are
ORINAL IMAGE CORNERS
OTL= 339 122
OTR= 1139 264
OBR= 1002 895
OBL= 221 718
RESULATANT IAMGE CORNERS
FTL= 280 193
FTR= 1074 195
FBR= 1070 806
FBL= 280 806
i am getting the above results.. in that results i am using the FTL and FBR values for point detection in .net code in that code i am using that values the exact values are not found. please help me for matlab code for transformation of image and getting the resultant corners. thanking you advance.

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!