How to crop a masked area (polygon shape) out of an image?
Show older comments
Hi all,
Now my code is like below:
I = imread('moon.tif');
figure;
imshow(I)
Poly_Mask = images.roi.Polygon(gca,'Position',[100 150; 200 250; 300 350; 150 450]);
As you can see, the example image is now masked with a polygon shape. I would like to crop the masked area (polygon shape) out of the image. Could you please suggest me how to do this? Thank you.
Accepted Answer
More Answers (1)
I cannot see your image. But I used a photo of my dog (because she wont sue me :D) to show the concept:
I=rgb2gray(imread("Tala1.jpg"));
x=[100 200 300 150];% your ROI x values
y=[150 250 350 450];% your ROI y values
[rows, columns,~] = size(I);
mask = imcomplement(poly2mask(x, y, rows, columns));
mul = immultiply(I,mask);
imshow(mul)

3 Comments
Chutiphon Moranon
on 30 Mar 2022
do you need to crop a polygon? you could crop out a rectangular section of image with imcrop(I, [x y dx dy]) and then calculate corrolation or convolution for feature matching.
Chutiphon Moranon
on 30 Mar 2022
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


