如何应用Matlab模糊C均值(fcm)输出进行图像分割

时间:2017-04-03 11:49:11

标签: matlab fuzzy-c-means

我有一个2D灰度图像(=数据),我试图用fcm.m进行分割:

Nc=2; %number of clusters is 2

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

如何应用fcm.m的输出来分割原始图像。我无法在网上找到一个有用的例子。

1 个答案:

答案 0 :(得分:2)

只做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