How do I get a specific part of the image that are not rectangular?
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jaeyong Oh
el 6 de Ag. de 2019
Comentada: Rik
el 3 de Jun. de 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 comentario
Rik
el 6 de Ag. de 2019
Depending on how you get that outline, the inpolygon function could help. Another strategy is using a tool to remove the keystone transformation.
Respuesta aceptada
Kavya Vuriti
el 9 de Ag. de 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 comentarios
van hai dang
el 3 de Jun. de 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
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!