MATLAB exercise program (incorrect image cutting)

Source: Internet
Author: User
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 = 0; % 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 );
H = V; % height of the original image
W = u; % width of the original image
Pro = W/H; % Aspect Ratio

% Although this program was written by myself, this affine transformation coefficient is still not very well expressed. It is my current understanding.
% Affine transform coefficient, indicating the tilt intensity of the transformed image. The value range is (0, 1), which indicates that the image is staggered to the right. If the value is 0, the image is not changed. If the value is 1, the image is vertically staggered and the image is not displayed. If the value is greater than 1, the image is staggered to the lower left.
The % range is (-), which is an error-cut image to the upper left. If it is-1, the image is vertically staggered without being explicitly displayed. If it is less than-1, the Right Bottom of the error-cut image is displayed. If the coefficient is too large or too small, the processing time will be long. If the coefficient is too large or too small, an error will be reported.
Aff_cof = 0.6;

Theta = jiaodu/180 * PI;
Rot1 = [cos (theta)-sin (theta) 0; sin (theta) Cos (theta) 0; 0 0 1]; % Rotation Transformation Matrix
Rot2 = [1 aff_cof * pro 0; aff_cof * (1/Pro) 1 0; 0 0 1]; % error tangent Transformation Matrix
Rot = rot2 * rot1; % Union Transformation Matrix
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 ))

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.