MATLAB Answers

How to crop a square that has a rotational angle?

Guilherme Pelegrini 님이 질문을 제출함. 9 Mar 2017
최근 활동 Selina 님이 댓글을 추가함. 1 Apr 2019
I need to crop one square of this image:
As you can see, I can't use imcrop() because it isn't horizontal, the squares has a rotational angle, and the region cropped need to be precisely on the edge of the line.
How can I do it?

  댓글 수: 0

로그인 to comment.

답변 수: 1

Massimo Zanetti 님의 답변 9 Mar 2017
Massimo Zanetti 님이 편집함. 9 Mar 2017

Inspect this: roipoly
Here is an example of what you can do:
%open an image
A = imread('coins.png');
%run roi tool, where you can define your polygon
BW = roipoly(A);
%extract image pixels in the roi
S = regionprops(BW,'ConvexImage','BoundingBox');
r = S.BoundingBox;
Q = A( round(r(2)) + (1:r(4)) , round(r(1)) + (1:r(3)) );
%display cropped image
im = imagesc(Q);
im.AlphaData = S.ConvexImage;
axis image; colormap gray;
In the roipoly window track your points manually to define a polygon, as in the picture:
Then, right-click and "Create Mask", you will get your cropped image:

  댓글 수: 1

Hi,
Is it possible to use rectangle crop using the ROI function? If so, can anyone please send a sample coding?

로그인 to comment.



Translated by