MATLAB: How to find connected components

connected components

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);

Best Answer

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: