如何在matlab中使用内置的fcm函数进行图像分割?

时间:2017-07-01 08:08:32

标签: matlab image-segmentation

我是matlab的新手。其实我要做视网膜血管分割。我已经使用kmeans聚类进行分割,但结果并不令人满意。现在我想尝试模糊c意味着聚类技术。但是我无法找到如何使用matlab内置函数来实现此目的。请指导我这个。我已经浏览了以下页面,但我无法理解如何将所有这些应用到我的图像中。

https://cn.mathworks.com/help/fuzzy/fcm.html 感谢

1 个答案:

答案 0 :(得分:1)

最小的工作示例:

% some sample rgb image
MyImage = imread('autumn.tif');
% display it
figure; imshow(MyImage)
% size of the image
sz = size(MyImage);
% reshape the image to column format (each color band into one column). I guess you
%also did this for the k-means. If not that's why you did get poor results.
ImageInColumnFormat = reshape(MyImage,[],sz(3));
% number of clusters you want
NumberOfClusters = 4;
% U shows how likely each pixel belongs to each cluster.
% double() is only necessary because the sample image is uint8 and fcm has trouble with that format. You may not have to do that.
[~,U] = fcm(double(ImageInColumnFormat),NumberOfClusters);
% Get for each pixel the most likely cluster
[~,Labels] = max(U,[],1);
% reshape it back into the image format
LabelsInImageFormat = reshape(Labels,sz(1),sz(2));
% show result
figure; imagesc(LabelsInImageFormat)