本文主要是介绍基于FCM的灰度图像的分割, matlab免费源码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
clear; close all; clc;%%读入图像,I = imread('figure');figure, imshow(I,[])[m, n, p] = size(I);
data = zeros(m*n,1);
I1 = reshape(double(I), m*n, p); %将数据转换为一列数据
data(1:m*n,1) = I1;cluster_n = 2; %聚类数目,自定义
options = [2, 500, 1e-5, 0]; %设定聚类参数
[center, U, obj_fcn] = fcm(data, cluster_n, options); %调用fcm实现聚类, matlab自带
cluster = cell(1, cluster_n);
cluster_pic = cell(1, cluster_n);
pic = cell(1, cluster_n);%%按聚类结果分割图像for i = 1:cluster_ncluster{i} = find( U(i,:)==max(U));cluster{i} = cluster{i}';cluster_pic{i} = data(1:m*n,1);temp = data(1:m*n,1);temp(cluster{i},:) = 0; cluster_pic{i} = cluster_pic{i}-temp;pic{i} = reshape(cluster_pic{i},m,n,p);figure;imshow(uint16(pic{i}));
end
这篇关于基于FCM的灰度图像的分割, matlab免费源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!