finding index inside a region
Show older comments
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
Accepted Answer
More Answers (1)
Andrei Bobrov
on 26 Jul 2011
BW = I==1;
[~,L] = bwboundaries(BW);
idx = find(L==2)
1 Comment
Image Analyst
on 26 Jul 2011
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.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!