2010-05-01 19:50:25 阅读7 评论0 字号:大中小
(2008-09-27 10:22:19)
模糊C均值聚类算法如下
1) 从n个数据集da
聚类中心集V0 = ( v1 , v2 ,..., vc ) ,确定隶属度矩阵U的加权指数expo 、{zd0}迭代次数max_iter、终止误差ε> 0。
2) 重复下列操作,直到‖Vb+1 - Vb ‖ <ε为止, b为当前
迭代次数。
%%%%%定义距离函数%%%%%%%%%%%
function out = distfcm(center, da
% 计算样本点到聚类中心的距离
% 输入:
%
%
% 输出:
%
out = zeros(size(center, 1), size(da
for k = 1:size(center, 1), % 对每一个聚类中心
en
%%%%%定义迭代函数%%%%%%
function [U_new, center, obj_fcn] = stepfcm(da
% 模糊C均值聚类时迭代的一步
% 输入:
%
%
%
%
% 输出:
%
%
%
mf = U.^expo;
center = (mf*da
dist = distfcm(center', da
obj_fcn = center';
tmp = dist.^(-2/(expo-1));
U_new = tmp./(on
%%%%%%%模糊模糊C均值聚类%%%%%%%
figure(1);
Ag=imread('2.bmp');
Ag=Ag(1:260,1:250,:);
subplot(211);imagesc(Ag,[0 1]); colormap(gray);title('聚类原图像');
Ag=double(Ag);
labAg=rgblab(Ag,0);
%%%%-------分离lab通道------
labAg1=labAg(:,:,1);
[m n]=size(labAg1);
%%%%--------将l通道的像素转换成一列----
labAg11=im2col(labAg1,[m n],'distinct');
%%%%----——确定样本点数和聚类中心个数————
da
cluster_ng=3;
expo=2;
max_iter = 100;
min_impro = 1e-5;
%%%--------初始化聚类中心----------
center=[Ag(83,45,1),Ag(25,47,1),Ag(132,245,1)];
dist=distfcm(center',labAg11);
tmp = dist.^(-2/(expo-1));
Ug = tmp./(on
obj_fcn_Ag = zeros(3,max_iter);
% ----------Main loop
for i = 1:max_iter,
end
%-----------将转换成一列的l通道的像素重新转换成数组------
x=size(Ug,2);
temp_Cg=zeros(m*n,4);
for i=1:x
end
Agd_num=col2im(temp_Cg(:,1),[m n],[m n],'distinct');
Agd_num1=Agd_num.*20;
figure(1);
subplot(212);image(Agd_num1);