MATLAB Answers

Select image region using point coordinates

33 ビュー (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2021 年 4 月 16 日 16:50
コメント済み: Image Analyst 2021 年 4 月 16 日 20:53
Hi, I was wondering if someone could do quickly and efficiently the selection of a region within the multiple ones that matlab manages to detect using the regionprops function in whose interior is a point that is defined by its x and y coordinates.

採用された回答

Image Analyst
Image Analyst 2021 年 4 月 16 日 18:08
The built-in function for this is bwselect(). Like
oneBlob = bwselect(multiBlobMask, x, y); % Return only the single blob that contains (x, y).
Here is the help:
bwselect
Select objects in binary image
Syntax
Description
BW2 = bwselect(BW,c,r) returns a binary image containing the objects that overlap the pixel (r, c). Objects are connected sets of on pixels, that is, pixels having a value of 1.
  2 件のコメント
Image Analyst
Image Analyst 2021 年 4 月 16 日 20:53
Alejandro, there is another related function that you maybe interested in. It's called imreconstruct(). With that function you give it a mask (with multiple blobs in it), and a "marker" image that has a subset of blobs. Then when you call imreconstruct, it will return only those blobs that overlap any part of a marker blob. So instead of giving it a coordinate or list of coordinates to tell it which blob(s) to extract, you give it an image.
So for example let's say you had an aerial photo of your neighborhood and wanted to find lawns that had white flowering trees on them (like many of them in my neighborhood do this week). So you'd have one mask of only the lawns, then another "marker" image of only the trees, then after you call imreconstruct, you'd get only those lawns that had the white flowering trees on them, and not any of the other lawns.

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

その他の回答 (1 件)

Matt J
Matt J 2021 年 4 月 16 日 17:51
regions=regionprops(yourImage,'PixelList');
detector=@(s) ismember([x,y], s.PixelList,'rows');
find( arrayfun( detector , region ) )
  1 件のコメント
Alejandro Fernández
Alejandro Fernández 2021 年 4 月 16 日 18:10
thank you so much for your help. However I think that the option offered by image Analist is much more compact and I have to give the acceptance to him.

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

Community Treasure Hunt

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

Start Hunting!

Translated by