1 简介
模糊 C 均值聚类(FCM)算法是一种基于非监督聚类算法。样本加权模糊 C 均值聚类(WFCM)算法是 FCM 算法的改进,该算法能够明显提高收敛速度和聚类的准确性。无论是 FCM 算法还是 WFCM 算法,对噪声都相对敏感,而且聚类数目仍然需要人工确定。在此提出一种改进算法,首先通过偏微分方程(PDE)降噪算法对原始脑 MRI医学图像进行处理;其次利用聚类有效性确定最佳聚类数目,对 WFCM 算法进行改进;最后利用本文改进算法对图像进行聚类分割。实验表明,该方法是一种具有自动分类能力、抗噪性较好的模糊聚类图像分割算法。
2 部分代码
%% Image segmentation by WFCM
% WFCM refer to 'Fuzzy cluster analysis and its application' by Teacher
% Gao, Published by xidian
% we first implement one thresholding segmentation, then auto
% multi-thresholding
% we also used two-dimentional gray histogram
% Algorithm by Teacher Xinbo Gao, implemented by Lin Zhao, VIPS Lab;
%% Code Follows
clear;clc;close all;
inputim = imread('TestImage\lena.bmp'); inputim = rgb2gray(inputim);
figure;imshow(inputim,[]);
% count 1D histogram or 2D histogram
[h,x] = imhist(inputim); figure;stem(x,h);
nst = imhist2(inputim);
count = 0:1:255;
% count = nst;
% compute the weighted coefficient wi
w = h'./sum(h');
% iteration to compute the center of clustering,here c=2
vc1 = 64; vc2 = 192; % initialization
v1 = 0; v2 = 0; n = 0;
while (abs(v1-vc1)>2)||(abs(v2-vc2)>2)
if n ~= 0
vc1 = v1; vc2 = v2;
end
% update uij
for j = 1:1:2
if j == 1
vc = vc1;
else
vc = vc2;
end
for i = 1:1:256
dij = norm(count(i)-vc);
di1 = norm(count(i)-vc1);
di2 = norm(count(i)-vc2);
u(i,j) = (dij/di1).^2+(dij/di2).^2;% m = 3
u(i,j) = 1/u(i,j);
end
end
for i = 1:1:256
for j = 1:1:2
if isnan(u(i,j))
u(i,j) = 0;
end
end
end
% update vj
x1 = w.*u(:,1)'.^3.*count;
x1 = sum(x1);
y1 = sum(w.*u(:,1)'.^3);
v1 = x1/y1;
x2 = w.*u(:,2)'.^3.*count;
x2 = sum(x2);
y2 = sum(w.*u(:,2)'.^3);
v2 = x2/y2;
n = n+1;
end
% compute the threholding
t = (vc1+vc2)/2;
T = repmat(t,size(inputim,1),size(inputim,2));
outputim = inputim>T;
outputim = double(outputim);
figure;imshow(outputim,[]);
3 仿真结果
4 参考文献
[1]陈梅, and 王健. "基于改进模糊C-均值聚类算法的图像分割." 现代电子技术 30.13(2007):2.
部分理论引用网络文献,若有侵权联系博主删除。
5 MATLAB代码与数据下载地址
见博客主页