problem in image segmentatiion by using FCM
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Image Analyst
2016-7-23
编辑:Image Analyst
2016-7-23
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Clustering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!