필터 지우기
필터 지우기

problem in image segmentatiion by using FCM

조회 수: 2 (최근 30일)
fred bnm
fred bnm 2016년 7월 23일
편집: Image Analyst 2016년 7월 23일
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.

답변 (1개)

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 Data Clustering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by