Extract and sort size of matrix where in the cell
Afficher commentaires plus anciens
clc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
end
3 commentaires
Stephen23
le 5 Déc 2021
What is the expected output?
Amir Azadeh Ranjbar
le 5 Déc 2021
Amir Azadeh Ranjbar
le 5 Déc 2021
Réponses (1)
Arjun
le 8 Jan 2025
I understand that you want to extract the connected componets in the descending order and also find out the components which are greater than a specific threshold size.
You can refer to the following workflow to achieve this:
- Find out the connected components using "bwconncomp"
cc=bwconncomp(im);
- Get the properties of the connected components using "regionprops"
stats = regionprops(cc, 'Area');
- Extract the sizes of the components
sizes = [stats.Area];
- Sort the components by descending order using "sort"
[sortedSizes, sortedIndices] = sort(sizes, 'descend');
- Specify the threshold and filter accordingly
filteredComponents = sortedIndices(sortedSizes > sizeThreshold);
Following are the documentation links of the functions used for your reference:
- bwconncomp: https://www.mathworks.com/help/releases/R2021a/images/ref/bwconncomp.html
- regionprops: https://www.mathworks.com/help/releases/R2021a/images/ref/regionprops.html
- sort: https://www.mathworks.com/help/releases/R2021a/matlab/ref/sort.html
I hope this will help!
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
