I have a sample image which contains a square. I rotated the image through a range of angle 30 to 50?
When I take the boundary size of the object in the rotated image (for these angle) I am getting values lesser than the boundary size of the object in the original sample image.
I am attaching a sample code for the same:
======================================================
Irot_new =imread('N:\work\tex\paper\square.bmp');Irot_new = rgb2gray(Irot_new);Irot_new = imbinarize(Irot_new);B = bwboundaries(Irot_new);boundary = B{1}; x = boundary(:,2); y = boundary(:,1); boundary_size = size(x) Irot_new = imrotate(Irot_new,-40,'nearest','crop');Irot_new = imbinarize(Irot_new);figureimshow(Irot_new);Irot_new = bwboundaries(Irot_new);boundary1 = Irot_new{1}; x = boundary1(:,2); y = boundary1(:,1); boundary_size = size(x)%======================================================
%I tried even without using the imrotate with the following code , but still the boundary size differ:
%======================================================I= imread('N:\work\tex\paper\square.bmp');I_rgb = rgb2gray(I);image= imbinarize(I_rgb);%image padding
[Rows, Cols] = size(image); Diagonal = sqrt(Rows^2 + Cols^2); RowPad = ceil(Diagonal - Rows) + 2;ColPad = ceil(Diagonal - Cols) + 2;imagepad = zeros(Rows+RowPad, Cols+ColPad);imagepad(ceil(RowPad/2):(ceil(RowPad/2)+Rows-1),ceil(ColPad/2):(ceil(ColPad/2)+Cols-1)) = image;t=30for i=1:1:4 rads=degtorad(t); %midpoints
midx=ceil((size(imagepad,1)+1)/2); midy=ceil((size(imagepad,2)+1)/2); imagerot=zeros(size(imagepad)); for i=1:size(imagerot,1) for j=1:size(imagerot,2) x= (i-midx)*cos(rads)+(j-midy)*sin(rads); y=-(i-midx)*sin(rads)+(j-midy)*cos(rads); x=round(x)+midx; y=round(y)+midy; if (x>=1 && y>=1 && x<=size(imagepad,2) && y<=size(imagepad,1)) imagerot(i,j)=imagepad(x,y); % k degrees rotated image
end end end B = bwboundaries(imagerot); boundary = B{1}; x = boundary(:,2); y = boundary(:,1); boundary_size = size(x) figure,imagesc(imagerot); colormap(gray(256)); t = t+10;end
=========================================================================
Can you please suggest why the boundary size varies while its determination? Any solution to keep the boundary size constant.
Best Answer