Finding zero's groups that are bounded in a matrix and there amounts
Mostra commenti meno recenti
Hi, i would to find "islands of zeros" in a matrix. for example, if i have this matrix i will get a vector that says [4] because there is just one group of bounded zeros and it is 4 elements. The size of the vector is the number of groups.
1 2 3 4 5
1 1 0 1 2
7 0 0 0 5
1 5 6 7 8
Is there an efficient way to do it?(build in functions).
thanks
Risposte (1)
A = [
1 2 3 4 5
1 1 0 1 2
7 0 0 0 5
1 5 6 7 8
4 0 2 0 0
5 1 3 8 2
]
p = regionprops(~A, 'area');
results = [p.Area]
6 Commenti
Guy Sivan
il 16 Dic 2021
thresh = 2;
A = [
1 2 3 4 5
1 1 0 1 2
7 0 0 0 5
1 5 6 7 8
4 0 2 0 3
0 1 3 8 2
]
BW = ~A;
BWfilt = bwareafilt(BW, [1 thresh]);
p = regionprops(BWfilt, 'area');
results = [p.Area]
BWfilt
Guy Sivan
il 16 Dic 2021
Walter Roberson
il 21 Dic 2021
If you want islands that are smaller than 2, then why are you expecting a 4 outcome?
Does the "2" refer to the number of islands you want? As in you want the two largest islands?
Guy Sivan
il 21 Dic 2021
A = [
1 2 3 4 5
1 1 6 1 2
7 0 6 0 5
7 5 6 7 8]
threshold = 2;
BWfilt = A <= threshold & A ~= 0
p = regionprops(BWfilt, 'area')
[p.Area]
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!