suppose I have a matrix I.
I =
4 4 4 4 4 4 4
4 1 1 1 1 3 0
4 1 3 3 1 3 0
4 1 3 3 1 3 0
4 1 1 1 1 3 0
4 4 4 4 4 4 4
idx is the index of 1's in the matrix including all 3's inside 1;
I need to find the index of those 3s those are inside 1s.
I tried with the following code.Perhaps this is not the correct one.
idx1=find(I(idx)==3);
How can I get that? can any body help?
Thanks

 採用された回答

Image Analyst
Image Analyst 2011 年 7 月 26 日

0 投票

This will work to get ONLY the 3's inside, not any old number.
binaryImage = I==1
filledImage = imfill(binaryImage, 'holes')
maskedImage = I .* filledImage
justThe3s = ismember(maskedImage, 3)
[rows cols] = find(justThe3s)
You could use either the logical indexes "justThe3s" or the rows and cols variables, whichever you mean by "indexes."

5 件のコメント

Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 7 月 27 日
Thanks
Nick Ward
Nick Ward 2021 年 4 月 23 日
Hi Image Analyst, how could I also specify the size of contiguous values above of >3 ? Say, a minimum region of 4x4 >3 within a larger martrix?
Thanks
Image Analyst
Image Analyst 2021 年 4 月 23 日
@Nick Ward, what do you mean by "Specify the size"? How about
binaryMap = largerMatrix > 3 % All elements > 3
% Get only those that are in contiguous regions of 16 or more
minAllowableSize = 16
bigBlobs = regionprops(binaryMap, minAllowableSize)
Nick Ward
Nick Ward 2021 年 4 月 23 日
Thanks for the reply.
I think this is what I'm looking for although I get these errors. Any ideas?
Image Analyst
Image Analyst 2021 年 4 月 23 日
@Nick Ward, attach your image/matrix, and m-file in a new question after reading this:

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 7 月 26 日

0 投票

BW = I==1;
[~,L] = bwboundaries(BW);
idx = find(L==2)

1 件のコメント

Image Analyst
Image Analyst 2011 年 7 月 26 日
This will get any collection of numbers inside a contiguous perimeter of 1's, not just the 3's. For example it would also find 4's, 42's, and 18's - whatever happened to be inside. Mohammad, see my answer if you want something that is more "tunable" to just one single number, if that is what you want.

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by