How to crop a square that has a rotational angle?

11 visualizzazioni (ultimi 30 giorni)
Guilherme Pelegrini il 9 Mar 2017
Risposto: Image Analyst il 19 Apr 2022
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (3)

Massimo Zanetti il 9 Mar 2017
Modificato: Massimo Zanetti il 9 Mar 2017
Inspect this: roipoly
Here is an example of what you can do:
%open an image
%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);
axis image; colormap gray;
In the roipoly window track your points manually to define a polygon, as in the picture:
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Selina il 1 Apr 2019
Hi,
Is it possible to use rectangle crop using the ROI function? If so, can anyone please send a sample coding?

Accedi per commentare.

cui,xingxing il 5 Mar 2022
I wrote an enhanced 'imcrop' function that supports rotating rectangle interception, but yours is an irregular quadrilateral, but you can also refer to what I wrote with 'estimateGeometricTransform2D' to estimate the conversion matrix, and then bring in the 'imwarp' function can be completed arbitrary shape interception, I hope it helps you
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Image Analyst il 19 Apr 2022
If you need to find the white lines automatically, you can try hough(), houghlines(), or radon().
I'm attaching a demo for how to use the radon transform to find the angle or rotation, and then it uses imrotate() to rotate the image until it's straight. Adapt as needed.
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Object Analysis in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by