摘要:

  基于FCM的在图像处理方面对噪声敏感的不足,本文通过引入空间模型建立空间模糊C均值聚类提高算法的鲁棒性,在此基础上,结合抑制式对算法进一步优化。最后,给图像加不同程度的噪声,通过MATLAB编程,分析比较各个算法的迭代次数、迭代时间、错误率以及均方根误差判断算法的优劣。

 一 空间模糊聚类概述

  之前对FCM做了简单介绍,通过实验发现其有一定的缺点,为此我们需要对算法进行一系列的优化,今天主要来分析一下空间模糊聚类,改善算法的鲁棒性。

1. FCM

在之前对FCM已经做过介绍,在此不再赘述,今天主要分析的是FCM在图像处理方面的应用,虽然FCM有着广泛适用性等优点,但FCM算法对噪声敏感这一点也是毋庸置疑的。FCM的目标函数:

                        The Robust Fuzzy C-means-LMLPHP

其中,yj指的是各个样本点对应的像素,取值为[0,255]。很明显,FCM并没有考虑到样本之间的空间相关性,只是分别考虑各个样本。减小噪声敏感程度的方法很多,比如在处理图像之前首先平滑图像,但这个方法会在一定程度上丢失样本中某些特性;还可以通过对隶属度函数的后处理等等,然而,我们今天讲到的空间模型是通过直接修改目标函数提高算法对噪声的鲁棒性。

2. The Roubst Fuzzy C-means(RFCM)

结合空间模型,为提高鲁棒性,RFCM在计算距离时考虑到每个样本点的邻域样本,也就将各个样本的空间相关性结合起来。在FCM算法的基础之上,得到RFCM的目标函数:

            The Robust Fuzzy C-means-LMLPHP

结合FCM的约束条件,引入拉格朗日因子进一步推导,得到的隶属度矩阵的计算公式为:                 

                The Robust Fuzzy C-means-LMLPHP

相应的聚类中心的计算公式为:

               The Robust Fuzzy C-means-LMLPHP

3. 抑制式

抑制式主要是对最大隶属度进行适当的放大,从而抑制其它隶属度,提高收敛速度,其中抑制式因子为:

The Robust Fuzzy C-means-LMLPHP

通过将隶属度函数与抑制式因子相乘,即可对算法进行抑制式修改。

二 MATLAB实现

为了比较算法的优劣,将算法作用于不同图像,并且分别加不同程度的高斯白噪声,分别比较算法的迭代次数,执行时间,错误率和均方根误差,这些在代码中均有说明。

1. RFCM

基于上面的介绍,可得到RFCM算法的步骤如下:

首先,给定一个由N个L维向量组成的数据集X以及所要分得的类别个数C,并且自定义隶属度矩阵

(1)初始化隶属度矩阵并归一

(2)根据聚类中心的计算公式更新聚类中心

(3)根据隶属度矩阵的计算公式更新隶属度

(4)不断的重复(2)直到收敛。

不知道大家有没有发现这和FCM的算法步骤大致是一样的,不同是在目标函数当中,当然体现在代码当中,而最终反映在算法的性能当中。

根据算法的步骤,采用MATLAB编程实现,在此导入MR图像,代码如下:

clear all
clc;

a=imread('MRI.jpg');
I=imnoise(a,'salt & pepper',0.03);
figure();
 imshow(I);title('加噪图像');

[height,width,c]=size(a);

    a=rgb2gray(a);
end

a=double(a);
[row,column]=size(a);
data = a(:);
data_n = size(data,);

beta = ;
cluster_num = 3;%将图像分为三类
default_options = [2.0;    % exponent for the partition matrix U
        ;    % max. number of iteration
        0.01;    % min. amount of improvement
        ];    % info display during iteration

options = default_options;

m = options();        % p,图像的质量参数
iter_num = options();        % Max. iteration 最大迭代次数
threshold = options();        % Min. improvement  最小进化步长
display = options();        % Display info or not 显示信息与否
costfunction = zeros(iter_num, );

tic
% 初始化隶属度并归一
membership = zeros(height,width,cluster_num);
:height
    :width
        member_sum=;
        :cluster_num
            membership(i,j,k)=rand();
            member_sum=member_sum + membership(i,j,k);
        end
        :cluster_num
            membership(i,j,p)=membership(i,j,p)/member_sum;
        end
    end
end

:iter_num %迭代次数控制

    %计算初始中心
    center = zeros(cluster_num,);
    :cluster_num
        sum = ;
        sum1 = ;
             :height
                :width
                 sum = sum + (membership(h,t,u).^m) * a(h,t);
                 sum1 = sum1 + membership(h,t,u).^m;
                 end
             end
             center(u) = sum/sum1;
    end

   :height
                    :width
                        up = i-;
                        down = i+;
                        left = j-;
                        right = j+;
                        )
                            up = ;
                        end
                        if( down > height)
                            down = height;
                        end
                        )
                            left = ;
                        end
                        if( right > width)
                            right = width;
                        end
                        s = ;
                         for x = up : down
                              for y = left : right
                                    :cluster_num
                                        :cluster_num
                                            s = s + membership(x,y,r).^m;
                                        end
                                        s = s - membership(x,y,u).^m;
                                    end
                              end
                         end
                    end
   end

    :height
        :width
            :cluster_num
                    costfunction(o) = costfunction(o) + membership(h,t,k).^m*(a(h,t) - center(k))^ + (beta/) * membership(h,t,k)^m*s;
                    tmp = ((a(h,t)-center(k))^  + beta * s).^(-/(m - ));
                    tomp = ;
                    :cluster_num
                        tomp = tomp + (a(h,t)-center(p))^;
                        tp = (tomp + beta * s) .^(-/(m - ));
                    end
                    membership(h,t,k) = tmp./tp;
            end
        end
    end

    %%%%%%归一化隶属度
    :height
        :width
            member_sum = ;
            :cluster_num
                member_sum = member_sum + membership(i,j,k);
            end
            :cluster_num
                membership(i,j,p) = membership(i,j,p) / member_sum;
            end
        end
    end

    if display,
        fprintf('Iteration count = %d, obj. fcn = %f\n', o, costfunction(o));
        %输出迭代次数和函数的结果
    end
    % check termination condition
    ,  %进化步长控制
        )) < threshold, break; end,
    end
end

 toc

  A = ones(height,width,);
:height
    :width
        ) == )
            A(i,j,) = ;
        end
        ) == )
            A(i,j,) = ;
        end
        ) / ) == )
            A(i,j,) = ;
        end
    end
end
A = reshape(A,,data_n);

  newing = zeros(row,column);
:row
    :column
        maxmembership=membership(i,j,);
        index=;
        :cluster_num
            if(membership(i,j,k)>maxmembership)
                maxmembership=membership(i,j,k);
                index=k;
            end
        end
        newing(i,j) = round( * (-(index-)/(cluster_num-)));
    end
end

B = reshape(newing,,data_n);
b = fix((max(B) - B(,)) / cluster_num);
:data_n
    ,i) == B(,)
        B(,i) = ;
    elseif (fix(B(,i) / b) == )
        B(,i) = ;
    elseif (fix(B(,i) / b)  == )
        B(,i) = ;
    else
        B(,i) = ;
    end
end
B(,) = ;

sum = ;
:data_n
    ,i) ~= B(,i))
        sum = sum + ;
    end
end
MCR = sum / data_n;
fprintf('MCR = %d\n',MCR);

S = ;
:data_n
    S = S + (A(,i) - B(,i)).^;
end

RMS = sqrt(S / (data_n * (data_n - )));
fprintf('RMS = %d\n',RMS);

figure();
imshow((uint8(newing)));
title('RFCM分割后的图像');

2. 抑制式RFCM

将抑制式因子作用于隶属度矩阵,采用MATLAB编程实现,代码如下:

clear all
clc;

a=imread('MRI.jpg');
I=imnoise(a,'salt & pepper',0.03);
figure();
 imshow(I);title('加噪图像');

[height,width,c]=size(a);

    a=rgb2gray(a);
end

a=double(a);
[row,column]=size(a);
data = a(:);
data_n = size(data,);

beta = ;
cluster_num = ;%将图像分为四类
default_options = [2.0;    % exponent for the partition matrix U
        ;    % max. number of iteration
        0.01;    % min. amount of improvement
        ];    % info display during iteration

options = default_options;

m = options();        % p,图像的质量参数
iter_num = options();        % Max. iteration 最大迭代次数
threshold = options();        % Min. improvement  最小进化步长
display = options();        % Display info or not 显示信息与否
costfunction = zeros(iter_num, );

tic
% 初始化隶属度并归一
membership = zeros(height,width,cluster_num);
:height
    :width
        member_sum=;
        :cluster_num
            membership(i,j,k)=rand();
            member_sum=member_sum + membership(i,j,k);
        end
        :cluster_num
            membership(i,j,p)=membership(i,j,p)/member_sum;
        end
    end
end

:iter_num %迭代次数控制

    %计算初始中心
    center = zeros(cluster_num,);
    :cluster_num
        sum = ;
        sum1 = ;
             :height
                :width
                 sum = sum + (membership(h,t,u).^m) * a(h,t);
                 sum1 = sum1 + membership(h,t,u).^m;
                 end
             end
             center(u) = sum/sum1;
    end

   :height
                    :width
                        up = i-;
                        down = i+;
                        left = j-;
                        right = j+;
                        )
                            up = ;
                        end
                        if( down > height)
                            down = height;
                        end
                        )
                            left = ;
                        end
                        if( right > width)
                            right = width;
                        end
                        s = ;
                         for x = up : down
                              for y = left : right
                                    :cluster_num
                                        :cluster_num
                                            s = s + membership(x,y,r).^m;
                                        end
                                        s = s - membership(x,y,u).^m;
                                    end
                              end
                         end
                    end
   end

    :height
        :width
            :cluster_num
                    costfunction(o) = costfunction(o) + membership(h,t,k).^m*(a(h,t) - center(k))^ + (beta/) * membership(h,t,k)^m*s;
                    tmp = ((a(h,t)-center(k))^  + beta * s).^(-/(m - ));
                    tomp = ;
                    :cluster_num
                        tomp = tomp + (a(h,t)-center(p))^;
                        tp = (tomp + beta * s) .^(-/(m - ));
                    end
                    membership(h,t,k) = tmp./tp;
            end
        end
    end

    %%%%%%归一化隶属度
    :height
        :width
            member_sum = ;
            :cluster_num
                member_sum = member_sum + membership(i,j,k);
            end
            :cluster_num
                membership(i,j,p) = membership(i,j,p) / member_sum;
            end
        end
    end

    %%%%%%%抑制式修改
    ha = ;
    :height
        :width
            :cluster_num
            ha = ha + membership(i,j,p).^;
            end
        end
    end

    alpha = ( cluster_num/(cluster_num - )) * ( -(/data_n) * ha);

     membership1 = membership.*alpha;

    :height
        :width
             [max_data,max_local] = max(membership(i,j,:));
             temembership = alpha.* membership(i,j,max_local) + ( - alpha);
             membership1(i,j,max_local) = temembership;
        end
    end
    membership = membership1 * alpha;

    :height
        :width
            member_sum = ;
            :cluster_num
                member_sum = member_sum + membership(i,j,k);
            end
            :cluster_num
                membership(i,j,p) = membership(i,j,p) / member_sum;
            end
        end
    end

    if display,
        fprintf('Iteration count = %d, obj. fcn = %f\n', o, costfunction(o));
        %输出迭代次数和函数的结果
    end
    % check termination condition
    ,  %进化步长控制
        )) < threshold, break; end,
    end
end

 toc

  A = ones(height,width,);
:height
    :width
        ) == )
            A(i,j,) = ;
        end
        ) == )
            A(i,j,) = ;
        end
        ) / ) == )
            A(i,j,) = ;
        end
    end
end
A = reshape(A,,data_n);

  newing = zeros(row,column);
:row
    :column
        maxmembership=membership(i,j,);
        index=;
        :cluster_num
            if(membership(i,j,k)>maxmembership)
                maxmembership=membership(i,j,k);
                index=k;
            end
        end
        newing(i,j) = round( * (-(index-)/(cluster_num-)));
    end
end

B = reshape(newing,,data_n);
b = fix((max(B) - B(,)) / cluster_num);
:data_n
    ,i) == B(,)
        B(,i) = ;
    elseif (fix(B(,i) / b) == )
        B(,i) = ;
    elseif (fix(B(,i) / b)  == )
        B(,i) = ;
    else
        B(,i) = ;
    end
end
B(,) = ;

sum = ;
:data_n
    ,i) ~= B(,i))
        sum = sum + ;
    end
end
MCR = sum / data_n;
fprintf('MCR = %d\n',MCR);

S = ;
:data_n
    S = S + (A(,i) - B(,i)).^;
end

RMS = sqrt(S / (data_n * (data_n - )));
fprintf('RMS = %d\n',RMS);

figure();
imshow((uint8(newing)));
title('SRFCM分割后的图像');

3.  结果比较

加噪3%:

The Robust Fuzzy C-means-LMLPHP

三种算法的处理结果:

The Robust Fuzzy C-means-LMLPHP 进而结合这三种算法的迭代次数、运行时间和错误率以及均方根误差这些判断算法的优劣,很明显的是SRFCM性能优于RFCM优于FCM,在这里我就不一一说明了,代码执行多次验证即可。除此之外,还可以采取NMI,ARI等加以说明。

为了进一步验证,也可以自定义图像(参上一篇),或者再通过其它图像验证。

版权:本文为博主原创文章,未经博主允许不得转载!

05-11 11:12