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

27 ビュー (過去 30 日間)
Jaeyong Oh
Jaeyong Oh 2019 年 8 月 6 日
コメント済み: Rik 2020 年 6 月 3 日
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
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
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
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
Rik
Rik 2020 年 6 月 3 日
Did you read the documentation for the repmat function?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by