资源描述:
《模式识别课程设计.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、模式识别课程设计关于黄绿树叶的分类问题成员:李家伟2015020907010黄哲2015020907006老师:程建学生签字:一、小组分工黄哲:数据采集以及特征提取。李家伟:算法编写设计,完成测试编写报告。二、特征提取选取黄、绿树叶各15片,用老师给出的识别算法进行特征提取%Extractthefeatureoftheleafclear,closeallI=imread('/Users/DrLee/Desktop/kmeans/1.jpg');I=im2double(I);figure,imshow(I)n=input('Pleaseinputthen
2、umberofthesampleregionsn:');h=input('Pleaseinputthewidthofthesampleregionh:');[Pos]=ginput(n);SamNum=size(Pos,1);Region=[];RegionFeatureCum=zeros((2*h+1)*(2*h+1)*3,1);RegionFeature=zeros((2*h+1)*(2*h+1)*3,1);fori=1:SamNumP=round(Pos(i,:));rectangle('Position',[P(1)P(2)2*h+12*h+1
3、]);holdonRegion{i}=I(P(2)-h:P(2)+h,P(1)-h:P(1)+h,:);RegionFeatureCum=RegionFeatureCum+reshape(Region{i},[(2*h+1)*(2*h+1)*3,1]);endholdoffRegionFeature=RegionFeatureCum/SamNum1~15为绿色树叶特征,16~30为黄色树叶特征,取n=3;h=1,表示每片叶子取三个区域,每个区域的特征为3*3*3维的向量,然后变为27*1的列向量,表格如下。绿色:黄色:三、在matlab中用K均值算法聚
4、类分析利用matlab中的K均值函数形式其中x为这30个样本的特征向量。将数据列表导入matlab空间,用列表读取函数X=xlsread(‘总和.numbers,'A2:AD28');[Idx,C,sumD,D]=kmeans(X’,2,’dist’,'sqEuclidean','rep',4);而后是分类情况的函数closeall;clearall;clc;load(‘D.mat')fori=1:15plot(D(i,1),D(i,2),’*b');holdon;plot(D(i+15,1),D(i+15,2),’*r');endx1=[sum(D(
5、1:15,1))sum(D(1:15,2))];x2=[sum(D(16:30,1))sum(D(16:30,2))];x1=x1./15;x2=x2./15;plot(x1(1,1),x1(1,2),'or');holdon;plot(x2(1,1),x2(1,2),'ob');holdon;xlabel(‘x1');ylabel('x2');text(x1(1,1)+0.1,x1(1,2)+0.2,’第一类');text(x2(1,1)+0.1,x2(1,2)+0.1,'第二类');之后利用算法查看分类情况:可以得知成功分成了2类。