problem in image segmentatiion by using FCM
3 views (last 30 days)
Show older comments
Hi,i want segmentation image by using FCM function. my code :
img = imread('wpeppers.jpg');
%convert to L*a*b
cform = makecform('srgb2lab');
lab_he = applycform(img,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_center,cluster_idx ] = fcm(ab,nColors);
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]), title('image labeled by cluster index');
please guide me about it. Error using reshape To RESHAPE the number of elements must not change.
0 Comments
Answers (1)
Image Analyst
on 23 Jul 2016
Edited: Image Analyst
on 23 Jul 2016
The size of cluster_idx is not equal to nrows * ncols. Try this:
fprintf('Size of cluster_idx = %d elements.\n', numel(cluster_idx));
fprintf('Rows * columns = %d elements.\n', nrows * ncols);
What do you see?
The fact is ab is a 2D variable with nrows * ncols * 2 elements, because you extracted two color channels into it. I'm not sure how fcm handles a 3D two color image because I don't have that function, but you need to look into it. It might give an index for every element rather than every 2-color pixel.
Anyway, why don't you try the Classification Learner app on the Apps tab of the tool ribbon. Maybe FCM is not the best approach. Experiment around with the others like kmeans, SVM, etc.
0 Comments
See Also
Categories
Find more on Data Clustering in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!