How to apply Matlab Fuzzy C-means (fcm) output for image segmentation

1.9k views Asked by At

I have a 2D grayscale image (= data) which I am trying to segment using fcm.m:

Nc=2; %number of clusters is 2

[centers,U] = fcm(data,Nc);

How do I apply the output of fcm.m to segment the original image. I cannot find a worked example online.

1

There are 1 answers

0
user2999345 On BEST ANSWER

just do reshape:

img = im2double(imread('cameraman.tif'));
Nc = 2; %number of clusters is 2

[centers,U] = fcm(img(:),Nc);
subplot(121);
imshow(reshape(U(1,:),size(img)),[])
title('fuzzy membership for class 1')
colorbar()
subplot(122);
[~,I] = max(U,[],1);
imshow(reshape(I,size(img)),[])
title('hard membership')
colorbar()

enter image description here