How to find connected components ?

2 次查看(过去 30 天)
I am using bwconncomp() to find the connected components in an image.But,I get error.What can I do to rectify it?
Error:
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was struct.
Error in images.internal.imageDisplayValidateParams (line 11)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 245)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in shitomashi1 (line 70)
figure,imshow(cc);
bwim1=adaptivethreshold(I,11,0.03,0);
figure,imshow(bwim1);
cc=bwconncomp(bwim1);
figure,imshow(cc);

采纳的回答

Shunichi Kusano
Shunichi Kusano 2019-2-6
The error seems to come from "imshow" function, since cc is not an image, but a structure.
You need to convert cc to labelimage by "labelmatrix", then show it by "imshow".
The following URL is helpful:
  2 个评论
ezhil K
ezhil K 2019-2-6
How should I use the code in the link.I don't understand.Can u please help me?
Shunichi Kusano
Shunichi Kusano 2019-2-6
This is one example:
labeled_image = labelmatrix(cc); % labeling each compoent
RGB_label = label2rgb(labeled,'spring','c','shuffle'); % colorization
imshow(RGB_label) % visualization
To see one of the connected component, please command like this:
A = false(size(bw)); % zero image
grain(cc.PixelIdxList{1}) = true; % input one to the area of the 1st component
imshow(grain) % visualization
hope this works.

请先登录,再进行评论。

更多回答(0 个)

类别

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