MATLAB exercise program (horizontal/vertical movement of images)

Source: Internet
Author: User
Cl;
Delta_x = 67; % must be an integer. The offset of horizontal movement. The value is right, and the negative value is left.
Delta_y =-89; % must be an integer. The offset of vertical movement is downward, and the negative value is upward.
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 );

Imgn = zeros (V + ABS (delta_y), u + ABS (delta_x ));
Rot = [1 0 0; 0 1 0; delta_y delta_x 1];
Inv_rot = inv (ROT );
Pix1 = [1 1] * rot; % pix1 (1), pix1 (2) are the Y, X
Pix4 = [v U 1] * rot; % pix4 (1), pix4 (2) are respectively y, X

% Move to bottom right
If delta_x> = 0 & delta_y> = 0
For Y = pix1 (1): pix4 (1)
For x = pix1 (2): pix4 (2)
PIX = [Y x 1] * inv_rot;
If pix (1)> = 0.5 & pix (2)> = 0.5 & pix (1) <= V & pix (2) <= u
Imgn (Y, x) = IMG (round (pix (1), round (pix (2 )));
End
End
End
End

% Move to lower left
If delta_x <0 & delta_y> = 0
For Y = pix1 (1): pix4 (1)
For x = pix1 (2): pix4 (2)
PIX = [Y x 1] * inv_rot;
If pix (1)> = 0.5 & pix (2)> = 0.5 & pix (1) <= V & pix (2) <= u
Imgn (Y, x-delta_x) = IMG (round (pix (1), round (pix (2 )));
End
End
End
End

% Move to the top left
If delta_x <0 & delta_y <0
For Y = pix1 (1): pix4 (1)
For x = pix1 (2): pix4 (2)
PIX = [Y x 1] * inv_rot;
If pix (1)> = 0.5 & pix (2)> = 0.5 & pix (1) <= V & pix (2) <= u
Imgn (y-delta_y, x-delta_x) = IMG (round (pix (1), round (pix (2 )));
End
End
End
End

% Move to top right
If delta_x> = 0 & delta_y <0
For Y = pix1 (1): pix4 (1)
For x = pix1 (2): pix4 (2)
PIX = [Y x 1] * inv_rot;
If pix (1)> = 0.5 & pix (2)> = 0.5 & pix (1) <= V & pix (2) <= u
Imgn (y-delta_y, x) = IMG (round (pix (1), round (pix (2 )));
End
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.