Cl;
H = 1; % index the first element in the PIX, that is, the height
W = 2; % index the second element in the PIX, that is, the width.
Jiaodu = 45; % rotation angle, clockwise
Img1_imread('corner.png '); % here V is the height of the original image, U is the width of the original image
Imshow (IMG); % here Y is the height of the transformed image, and X is the width of the transformed Image
[V u] = size (IMG );
Theta = jiaodu/180 * PI;
Rot = [cos (theta)-sin (theta) 0; sin (theta) Cos (theta) 0; 0 0 1];
Inv_rot = inv (ROT );
Pix1 = [1 1] * rot; % coordinate of the upper left point of the transformed Image
Pix2 = [1 U 1] * rot; % coordinates of the upper right point of the transformed Image
Pix3 = [V 1 1] * rot; % coordinate of the lower left point of the transformed Image
Pix4 = [v U 1] * rot; % coordinate of the lower right point of the transformed Image
Height = round (max ([ABS (pix1 (H)-pix4 (H) + 0.5 ABS (pix2 (H)-pix3 (H) + 0.5]); % height of the transformed Image
Width = round (max ([ABS (pix1 (w)-pix4 (w) + 0.5 ABS (pix2 (w)-pix3 (w) + 0.5]); % width of the transformed Image
Imgn = zeros (height, width );
Delta_y = ABS (min ([pix1 (h) pix2 (h) pix3 (h) pix4 (h)]); % get the offset of the negative axis exceeding y
Delta_x = ABS (min ([pix1 (w) pix2 (w) pix3 (w) pix4 (w)]); % get the offset of the X-direction negative axis exceeding
For Y = 1-delta_y: height-delta_y
For x = 1-delta_x: width-delta_x
PIX = [Y x 1] * inv_rot; % use the coordinates of the transformed image points to find the coordinates of the original image points,
% Otherwise, the pixels of some transformed images cannot be fully filled.
If pix (h)> = 0.5 & pix (w)> = 0.5 & pix (h) <= V & pix (w) <= u
Imgn (Y + delta_y, x + delta_x) = IMG (round (pix (h), round (pix (w )));
End
End
End
Figure, imshow (uint8 (imgn ))