How do I get a specific part of the image that are not rectangular?
조회 수: 26 (최근 30일)
이전 댓글 표시
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
Rik
2019년 8월 6일
Depending on how you get that outline, the inpolygon function could help. Another strategy is using a tool to remove the keystone transformation.
채택된 답변
Kavya Vuriti
2019년 8월 9일
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
van hai dang
2020년 6월 3일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!