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

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

我有一个 2D 灰度图像(= 数据),我正在尝试使用 fcm.m:

对其进行分割
Nc=2; %number of clusters is 2

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

如何应用 fcm.m 的输出来分割原始图像。我在网上找不到有效的示例。

就这样 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()