DAY13 matlab Cartesian coordinate system for image rotation

Source: Internet
Author: User
Tags cos

% 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.