How to find connected components ?

5 ビュー (過去 30 日間)
ezhil K
ezhil K 2019 年 2 月 6 日
コメント済み: Shunichi Kusano 2019 年 2 月 6 日
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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by