How do I get a specific part of the image that are not rectangular?

29 vues (au cours des 30 derniers jours)
Jaeyong Oh
Jaeyong Oh le 6 Août 2019
Commenté : Rik le 3 Juin 2020
Hi,
I am trying to take specific region of an image to get average pixel intensity of that region.
So far I only know how to crop and take the rectangular parts of an image.
But I have done some searching and realized that cropping is only for rectangular parts that are parallel to x and y axis.
Attached image '1' shows the original image and '1..lines drawn' shows the regions that I want to take.
They are not rectangular or anything, not even parallelograms or trapazoids.
How can I go about this problem?
Also, if possible, It will be awesome if you could give some specific explanation for each code since I am not that familiar with MATLAB in general.. thank you!
  1 commentaire
Rik
Rik le 6 Août 2019
Depending on how you get that outline, the inpolygon function could help. Another strategy is using a tool to remove the keystone transformation.

Connectez-vous pour commenter.

Réponse acceptée

Kavya Vuriti
Kavya Vuriti le 9 Août 2019
I think you can try drawing the polygon using drawpolygon function.
Im=imread('1.jfif'); %read image
h=drawpolygon;
The above commands open the image and enables to draw polygonal Region of interest. The vertices of the polygon are stored in the object “h”. Then try using roipoly function which returns binary mask of the object with pixels inside the region of interest set to 1 and pixels outside to 0. Then use bwareafilt function to filter the object within the ROI and bwconvhull to obtain the outer cover of region to be cropped. Then multiply the obtained mask with original image to obtain the cropped image using immultiply function.
A=roipoly(Im,x,y); % x and y are the x and y coordinates of the vertices of the polygon
A = bwareafilt(A,1);
A = bwconvhull(A);
croppedImg = immultiply(Im,repmat(A,[1 1 3]));
imshow(croppedImg);
  3 commentaires
van hai dang
van hai dang le 3 Juin 2020
croppedImg = immultiply(Im,repmat(A,[1 1 3]));
For this code, I cannot run with my cases. I do not know why you used [1 1 3].
please explain to me. thanks
Rik
Rik le 3 Juin 2020
Did you read the documentation for the repmat function?

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by