《测控技术与仪器毕业设计里的程序》由会员分享,可在线阅读,更多相关《测控技术与仪器毕业设计里的程序(7页珍藏版)》请在金锄头文库上搜索。
1、-111111111-1;-111111111-1;-111-1-1-1 -1-1 -1-1;-111-1-1-1 -1 -1 -1 -1;-111111111-1;-111111111-1 ;-1 -1 -1 -1 -1 -1 1 1 -1;array one=-1-1 -1 -1 1 1 -1 -1 -1 -1;-1-1 -1 -1 11 -1 -1 -1 -1;-1 -1 -1 -111 -1 -1 -1 -1;-1-1-1 -111 -1 -1 -1-1;-1 -1 -1 -111 -1 -1 -1 -1;-1-1-1 -111 -1 -1 -1-1;-1 -1 -1 -111 -1
2、-1 -1 -1;-1-1-1 -111 -1 -1 -1-1;-1 -1 -1 -111 -1 -1 -1 -1;-1-1-1 -111 -1 -1 -1-1;array two=-11 1 1 1 1 1 11 -1;-1 1 111 1 1 1 1 -1;% st andard number array ;矩阵填充,数字模型建立-1-1 -1 -1 -1 -1 -1 1 1 一1;一1%plo t st andard number figure 画出标准数字图像Array_one=imresize(array_one,20);subplot( 3,2,1) imshow(Array_on
3、e) title(stand number)Array_two=imresize(array_two,20);subplot( 3,2,2) imshow(Array_two) title(stand number)% -create hopfield net 仓【J建 Hopfield网络T=array_one;array_two;net=newhop(T);rand(state,0);for i=1:100a=rand;if a0.1array_one(i)=-array_one(i); array_two(i)=-array_two(i);endendno1=array_one; no2
4、=array_two; subplot(3,2,3) NO1=imresize(no1,20);imshow(NO1)title(noisy number)subplot(3,2,4)NO2=imresize(no2,20);imshow(NO2)title(noisy number)% plot identify figurenoise1=(no1);tu1=sim(net,10,10,noise1); tu110subplot( 3,2,5)imshow(imresize(tu110,20) title(identifynumber) noise2=(no2);tu2=sim(net,10
5、,10,noise2);tu210subplot(3,2,6) imshow(imresize(tu210,20) title(identify number)array_f=-1 1 11 1 11 11 -1;-111 111 111-1;-111 -1 -1-1 -1-1-1 -1;-111 -1 -1 -1 -1-1-1 -1;-111 1 1 11 1 1-1;-1 1 1111 111 -1;-111 -1 -1-1 -1-1-1 -1;-111 -1 -1 -1 -1-1-1 -1;-111 -1 -1-1 -1-1-1 -1;-111 -1 -1 -1 -1-1-1 -1;ar
6、ray :h=-1 1 1 -1 -1 -1 -1 1 1-1;-111 -1 -1 -1-11 1 -1;-111 -1 -1-1 -11 1-1;-111-1-1-1-111 -1;-111 1 1 11 1 1-1;-1 111 111 11-1;-111 -1 -1-1 -11 1-1;-111-1-1-1-111 -1;-111 -1 -1-1 -11 1-1;-111-1-1-1-111 -1;%plo t st andard number figure 画出标准数字图像Array_f=imresize(array_f,20);subplot( 3,2,1)imshow(Array
7、_f)title(stand number)Array_h=imresize(array_h,20);subplot( 3,2,2)imshow(Array_h)title(stand number)% -create hopfield net 仓【J建 Hopfield网络T=array_f;array_h;net=newhop(T);rand(state,0);for i=1:100a=rand;if a0.1-array_h(i);array_f(i)=-array_f(i); array_h(i)=endendno1=array_f;no2=array_h;subplot(3,2,3)
8、NO1=imresize(no1,20);imshow(NOI)title(noisy number)subplot(3,2,4)NO2=imresize(no2,2O);imshow(NO2)title( noisy number)% plot identify figurenoise1=(no1);tu1=sim(net,10,10,noise1);tu110subplot( 3,2,5)imshow(imresize(tu110,20)title(identifynumber)noise2=(no2);tu2=sim(net,10,10,noise2);tu210subplot(3,2,
9、6)imshow(imresize(tu210,20)title(identify number)概率神经网络椒盐(高斯)噪声% dig it al_rec.m 手写体数字的识别%清理工作空间clear,clcclose all%读取数据disp(开始读取图片.);I = getPicData();% load Idisp(图片读取完毕)%特征提取x0 = zeros(14, 1000);disp(开始特征提取.)for i=1:1000%先进行中值滤波tmp = medfilt2(I(:,:,i),3,3);%得到特征向量t= getFeature(tmp); x0(:,i) = t(:);
10、end%标签label为长度为1000的列向量label = 1:10;label = repmat(label,100,1);label = label(:); disp(特征提取完毕)%神经网络模型的建立ticspread = .1;%归一化x, se = mapminmax(xO);%创建概率神经网络net = newpnn(x, ind2vec(label);ti = toc;fprintf(建立网络模型共耗时%f secn , ti);%测试%输入原数据样本进行测试labO = net(x);%将向量化的类别lab0转化为标量类别lablab = vec2ind(lab0);%计算正
11、确率rate = sum(label = lab) / length(label);fprintf(训练样本的测试正确率为n %d%n , round(rate*100);%带噪声的图片测试I1 = I;%椒盐噪声的强度nois = 0.45;fea0 = zeros(14, 1000);for i=1:1000tmp(:,:,i) = I1(:,:,i);%添加噪声imnoise(double(tmp(:,:,i), salt & pepper, nois);tmpn(:,:,i)=imnoise(double(tmp(:,:,i),gaussian,O, 0.1);%中值滤波 tmpt(
12、:,:,i)medfilt2(tmpn(:,:,i),3,3);%提取特征向量t( :,i) = getFeature(tmpt( :,:,i); fea0(:,i) = t( :,i);endfigureimshow(tmpn(:,:,100)figureimshow(tmpn(:,:,200)figureimshow(tmpn(:,:,300)figureimshow(tmpn(:,:,400)figureimshow(tmpt(:,:,100)figureimshow(tmpt(:,:,200)figureimshow(tmpt(:,:,300)figureimshow(tmpt(:,:
13、,400)%归一化fea = mapminmax( apply ,fea0, se);%测试tlabO = net(fea);tlab = vec2ind(tlab0);%计算噪声干扰下的正确率rat = sum(tlab = label) / length(tlab);fprintf(带噪声的训练样本测试正确率为n %d%n , round(rat*100);基于SVM支持向量机的字符识别程序function Chapter_CharacterRecognitionUsingLibsvm%基于SVM的手写字体识别close all;clear;clc;format compact;%载入训练数据%利用uigetfile函数交互式选取训练样本FileName,Pa