基于MATLAB和模糊聚类分析的图像分类

基于MATLAB和模糊聚类分析的图像分类

在做数学建模校赛的时候,队伍选择了一道图像分类题,采用了模糊聚类分析的方法,这里记录下对这个方法的学习心得。

从本地导入文件

如下为从多张图片中提取出来的相同字符,本文将以“解”字为例,来进行讨论。

// ***处填入绝对路径
photo1= imread('C:\***\***\1.jpg');
调整图片灰度与亮度

先调整图片的灰度和亮度,方便下面的操作:

photo1_1 = imadjust(photo1, [0.2 0.5],[0 1],4);
M = stretchlim(photo1_1); 
photo1_2 = imadjust(photo1_1, M, [])

查看调整前后的图片对比:

figure,
subplot(131),imshow(uint8(photo1));
subplot(132),imshow(uint8(photo1_1));
subplot(133),imshow(uint8(photo1_2));

结果如下:
在这里插入图片描述

进行灰度化处理

这里采用加权平均法进行处理

y1=1/3*photo1_2(:,:,1) + 1/3*photo1_2(:,:,2) + 1/3*photo1_2(:,:,3);
计算模糊相似矩阵

研究的样本总体为s张分辨率为mn的图像,对每张图像进行灰度化处理得到其相应的mn维灰度矩阵。
在这里插入图片描述
建立模糊相似矩阵R , 其中 ,r(p,q)为图像p与图像q的相似系数,表示两者的相似程度,这里采取绝对值减数法:
在这里插入图片描述
为了方便起见,先将28个二维矩阵,合并成一个三维矩阵

%合并矩阵为40*40*28
yy = zeros(40,40,28);
for i=1:28
yy(:,:,i) = eval(['y', num2str(i)]);
end

%计算模糊相似矩阵
R = zeros(28,28);
sum = 0;
for p=1:28
    for q = 1:28
    sum = 0;
        for i = 1:28
            for j = 1:28
                sum=sum+ abs(yy(i,j,p)-yy(i,j,q) );
            end
        end
        R(p,q)=1-sum*(1/1000000);
    end
end

%输出模糊相似矩阵
R
聚类

求得模糊相似矩阵之后进行聚类,先求得R的传递闭包,再选择适当的值来截取矩阵,截取规律如下,矩阵中大于等于该值的数取1,小于该值的数取0。
在这里插入图片描述

%求传递闭包
a=size(R);
B=zeros(a);
flag=0;
while flag==0  
  for i= 1: a  
    for j= 1: a
      for k=1:a
	%RR内积,抄先取小再取大袭
	B(i,j) = max(min(R(i,k),R(k,j)),B(i,j)) ;   
      end
    end
  end
  if B==R
    flag=1;
  else
    R=B;%循环计算baiR传递闭du包
  end
end

截矩阵时有一个小技巧,先将二维矩阵拉成一维矩阵,再进行排序,从值较大的地方开始截取。

%求有多少个不相等数据
R1 = R;
R1 = R1(:); %拉成一维,
n = length(unique(B)); % 取唯一,算长度,可得要的不同值个数 
n %不同值的个数
R2 = unique(R1,'rows'); 

本文采取0.9638作为截取值。

RR = R;
for i =1:28
    for j = 1:28
        if RR(i,j)>=0.9638
           RR(i,j)=1else
           RR(i,j) = 0;
        end
    end
end

当且仅当截取后的矩阵中对应的列向量相等,则其对应的样本可分为同一类。

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Fuzzy Cluster Analysis -Methods for Classification,Data Analysis and Image Recognition Frank Hoppner, Frank Klawonn, Rudolf Kruse,Thomas Runkler 著 目录 1 Basic Concepts 1.1 Analysis of data 1.2 Cluster analysis 1.3 Objective functilm-based cluster analysis 1.5 Special objective functions 1.6 A principal clustering algorithm 1. 7 Unknown number of clusters problem 2 Classical Fuzzy Clustering Algorithms 2.1 The fuzzy c-means algorithm 2.2 The Gustafson-Kessel algorithm 2.3 The Gath-Geva algorithm 2.4 Simplified versions of GK and GG 2.5 Computational effort 3 Linear and Ellipsoidal Prototypes 3.1 The fuzzy c-varieties algorithm 3.2 The adaptive fuzzy clustering algorithm 3.3 Algorithms by Gustafson/Kessel and Gath/ Geva 3.4 Computational effort 4 Shell Prototypes 4.1 The fuzzy c-shells algorithm 4.2 The fuzzy c-spherical shells algorithm 4.3 The adaptive fuzzy. c-shells algorithm 4.4 The fuzzy c-ellipsoidal shells algorithm 4.5 The fuzzy c-ellipses algorithm 4.6 The fuzzy c-quadric shells algorithm 4.7 The modified FCQS algorithm 4.8 Computational effort 5 Polygonal Object Boundaries 5.1 Detection of rectangles 5.2 The fuzzy c-rectangular shells algorithm 5.3 The fuzzy c-2-rectangular sl}ells algorithm 5.4 Computational effort 6 Cluster Estimation Models 6.1 AO membership functions 6.2 ACE membership functions 6.3 Hyperconic clustering (dancing cones) 6.4 Ptototype defuzzification. 6.5 ACE for higher-order prototypes 6.6 Acceleration of the Clustering Process 6.6.1 Fast Alternating Cluster Estimation (F.-\CE) 6.6.2 Regular Alternating Cluster Estimation (rACE) 6. 7 Comparison: AO and ACE 7 Cluster Validity 7.1 Global validity measures 7.1.1 Solid clustering validity measures 7.1.2 Shell clustering validity measures 7.2 Local validity measures 7.2.1 The compatible cluster merging algorithm 7.2.2 The unsupervised FCSS algorithm 7.2.3 The contour density criterion 7.2.4 The unsupervised (M)FCQS algorithm 7.3 Initialization by edge detection 8 Rule Generation with Clustering 8.1 From membership matrices to membership functions 8.1.1 Interpolation 8.1.2 Projection and cylindrical extension 8.1.3 Convex completion 8.1.4 Approximation 8.1.5 Cluster estimation with ACE 8.2 Rules for fuzzy classifiers 8.2.1 Input space clustering 8.2.2 Cluster projection 8.2.3 Input output product space clustering 8.3 Rules for function approximation 8.3.1 Input ouput product space clustering 8.3.2 Input space clustering 8.3.3 Output space clustering 8.4 Choice of the clustering domain Appendix A.1 Notation A.2 Influence of scaling on the cluster partition A.3 Overview on FCQS cluster shapes A.4 Transformation to straight lines References Index

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值