필터 지우기
필터 지우기

How to find the size of the biggest component ?

조회 수: 7 (최근 30일)
Sultan
Sultan 2017년 7월 13일
답변: Image Analyst 2017년 7월 13일
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)

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 13일
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"

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 7월 13일
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".

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by