Most efficient way to find the indices of rectangular annuli in a 2D matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sai Prasanth
am 4 Nov. 2020
Bearbeitet: Matt J
am 12 Nov. 2020
Hello,
I have a 2D matrix of dimensions 400 x 400. I am interested in extracting the indices of the regions marked in pink, green, and yellow in the below figure. One way to go about this would be: First, find the indices where the X > 100 & X < 300 & Y > 100 & Y < 300 and that is the pink region. Here, the Xs represent the columns and the Ys represent the rows. For the green and yellow regions, it will be useful if I can do something like: find the indices where the X > 50 & X < 350 & Y > 50 & Y < 350 and add an additional condition that the indices should not correspond to the pink region. Similarly, the yellow region is simply all the indices that do not correspond to the pink or green regions. How do I implement this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/403445/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Matt J
am 5 Nov. 2020
Bearbeitet: Matt J
am 5 Nov. 2020
I=[ones(1,50), 2*ones(1,50), 3*ones(1,100)];
I=[I,flip(I)];
pink = (I==3 & I.'==3);
green = (I>=2) & (I.'>=2)&~pink;
yellow = ~(pink|green);
imshow(pink)
imshow(green)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!