• 大小: 604KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: Matlab
  • 标签: 图像处理  matlab  

资源简介

聚类分割算法是图像处理中的基本操作,文件中包含了使用模糊C-均值实现聚类分割的算法原理以及MAtlab源程序

资源截图

代码片段和文件信息

function [IX2]=fcm(IM);
%IM是输入的源图像
%IX2是分类结果
IM=imread(‘wwwlt163com200806191143.jpg‘);

IM=IM(::1);
figure(1)
imshow(uint8(IM))
[maxXmaxY]=size(IM);
IM=double(IM);

IMM=cat(4IMIMIMIM);
%初始化聚类中心(4类)
cc1=7;
cc2=70;
cc3=180;
cc4=240;
ttFcm=0;
while(ttFcm<15)
    ttFcm=ttFcm+1;
    c1=repmat(cc1maxXmaxY);
    c2=repmat(cc2maxXmaxY);
    c3=repmat(cc3maxXmaxY);
    c4=repmat(cc4maxXmaxY);
    c=cat(4c1c2c3c4);
    ree=repmat(0.000001maxXmaxY);
    ree1=cat(4reereereeree);
    distance=IMM-c;
    distance=distance.*distance+ree1;
    daoshu=1./distance;
    daoshu2=daoshu(::1)+daoshu(::2)+daoshu(::3)+daoshu(::4);
    %计算隶属度u
        distance1=distance(::1).*daoshu2;
        u1=1./distance1;
        distance2=distance(::2).*daoshu2;
        u2=1./distance2;
        distance3=distance(::3).*daoshu2;
        u3=1./distance3;
        distance4=distance(::4).*daoshu2;
        u4=1./distance4;
    %计算聚类中心z
        ccc1=sum(sum(u1.*u1.*IM))/sum(sum(u1.*u1));
        ccc2=sum(sum(u2.*u2.*IM))/sum(sum(u2.*u2));
        ccc3=sum(sum(u3.*u3.*IM))/sum(sum(u3.*u3));
        ccc4=sum(sum(u4.*u4.*IM))/sum(sum(u4.*u4));
        
        
    tmpMatrix=[abs(cc1-ccc1)/cc1abs(cc2-ccc2)/cc2abs(cc3-ccc3)/cc3abs(cc4-ccc4)/cc4];
    
        pp=cat(3u1u2u3u4);
        for i=1:maxX
            for j=1:maxY
                if max(pp(ij:))==u1(ij)
                    IX(ij)=1;
                elseif max(pp(ij:))==u2(ij)
                    IX2(ij)=2;
                elseif max(pp(ij:))==u3(ij)
                    IX2(ij)=3;
                else
                    IX2(ij)=4;
                end
            end
        end
     %判结束条件
        if max(tmpMatrix)<0.0001
            break;
        else
            cc1=ccc1;
            cc2=ccc2;
            cc3=ccc3;
            cc4=ccc4;
        end
      for i=1:maxX
            for j=1:maxY
                if IX2(ij)==1
                    IMMM(ij)=240;
                elseif IX2(ij)==3
                    IMMM(ij)=180;
                elseif IX2(ij)==2 
                    IMMM(ij)=70;
                else
                    IMMM(ij)=7;
                end
            end
        end
        
        %显示每次聚类分割结果
        figure(2);
        imshow(uint8(IMMM));
end
    for i=1:maxX
            for j=1:maxY
                if IX2(ij)==4
                    IMMM(ij)=240;
                elseif IX2(ij)==3
                    IMMM(ij)=180;
                elseif IX2(ij)==2 
                    IMMM(ij)=70;
                else
                    IMMM(ij)=7;
                end
            end
        end
%显示最终分类结果
IMMM=uint8(IMMM);
figure(3);
imshow(IMMM);
end

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     604864  2011-03-10 12:27  实验一\123.bmp

     文件       2858  2011-03-10 12:27  实验一\fcm4.asv

     文件       2858  2011-03-10 12:27  实验一\fcm4.m

    ..A..H.     14848  2011-03-10 12:27  实验一\Thumbs.db

     文件      40547  2011-03-10 12:27  实验一\wwwlt163com200806191143.jpg

     文件     410362  2011-03-10 12:27  实验一\实验一  模糊聚类的图像分割.docx

     文件      15529  2011-03-10 12:27  实验一\附录1 实验一参考程序.docx

     目录          0  2011-05-29 16:59  实验一

----------- ---------  ---------- -----  ----

              1091866                    8


评论

共有 条评论