How to find the size of the biggest component ?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sultan
el 13 de Jul. de 2017
Respondida: Image Analyst
el 13 de Jul. de 2017
I am trying to find the size of the biggest cluster and the dimension of it. Is the code that I am using gives the size of the biggest cluster. On the other words, is the size of the biggest cluster,the number of pixels in the cluster? Then how to find the dimension of the biggest cluster?
A=rand(100);
A=A<.5
connected_comp=bwconncomp(A,4);
cluster_size=cellfun(@numel,connected_comp.PixelIdxList)
[biggest,idx] = max(numPixels)
0 comentarios
Respuesta aceptada
Walter Roberson
el 13 de Jul. de 2017
Measuring the number of pixels in the cluster is a valid measure of size that is correct for a number of purposes.
Sometimes what is desired would correspond to using imfill('holes') and then counting the pixels: this would be the area "inside" the boundaries.
Sometimes you want to take the convex hull and find its area; one way of finding this is regionprops('convexarea')
Sometimes you want the area of the bounding box; regionprops('area')
With regards to "dimension", sometimes you mean the length or width of the bounding box; regionprops('boundingbox') and extract the appropriate information.
Sometimes you mean the length of the major axes when approximating as an ellipse; regionprops('majoraxeslength')
Sometimes you want to find the two pixels that are furthest apart in Euclidean space and call that distance the "dimension"
0 comentarios
Más respuestas (1)
Image Analyst
el 13 de Jul. de 2017
It looks like by "cluster" you really mean a "connected component". But you're doing it in a weird and complicated way. The standard way is to use regionprops() to measure the areas of all blobs
props = regionprops(connected_comp, 'Area');
allAreas = [props.Area]; % List of the areas for ALL blobs in the image.
[maxArea, indexOfBiggestBlob] = max(allAreas); % Info on the biggest blob ONLY.
regionprops() can measure things other than area but I'm not sure what you meant by "size" or "dimension".
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!