% Right angle coordinate system for image rotation
Im=rgb2gray (Imread (' robot.jpg '));
Figure,imshow (IM);
[Row,col]=size (IM);
A=PI/6; % counterclockwise rotation 30 degrees
% get the initial matrix of rows
R1=repmat (1:row,row,1);
I=r1 ';
% gets the initial matrix of the column
J=repmat (1:col,col,1);
i1=zeros (Row,col);
for N=1:col
I1 (m,n) =round (M*cos (a)-n* Sin (a)); % gets the rotated I pixel value and rounding
end
end
J1=zeros (Row,col);
For M=1:row
For N=1:col
J1 (m,n) =round (M*sin (a) +n*cos (a)); % gets the rotated J-pixel value and rounding
End
End
% determines whether the i,j after rotation is less than 0 coordinate adjustment
if min (min (i1)) <min (min (j1) )
if min (min (i1)) <0
k=abs (min (i1));
new_min=min (min (i1)) + (k+1);
A=i1+ones (Row,col) * (k+1);
End
ElseIf min (min (j1)) <0
k=abs (min (J1));
new_min=min (min (J1)) + (k+1);
A=j1+ones (Row,col) * (k+1);
End
New_max_i=max (Max (A)); % Maximum row
New_max_j=max (Max (J1)); % Maximum Column
G=zeros (New_max_i,new_max_j); % Construction blank New canvas
% Next input data fill
For M=1:row
For N=1:col
G (A (m,n), J1 (M,n)) =im (m,n);
End
End
Figure,imshow (Uint8 (G));
DAY13 matlab Cartesian coordinate system for image rotation