www.gusucode.com > 字母去噪源码程序 > 字母去噪源码程序/sigezimu.m

    clc;
clear;
close all;
% ------------------------standard letter array-----------------------

letterE=[-1 1 1 1 1 1 1 1 1 -1; -1 1 1 1 1 1 1 1 1 -1;...
         -1 1 1 -1 -1 -1 -1 -1 -1 -1; -1 1 1 -1 -1 -1 -1 -1 -1 -1;...
         -1 1 1 1 1 1 1 1 1 -1; -1 1 1 1 1 1 1 1 1 -1;...
         -1 1 1 -1 -1 -1 -1 -1 -1 -1; -1 1 1 -1 -1 -1 -1 -1 -1 -1;...
         -1 1 1 1 1 1 1 1 1 -1; -1 1 1 1 1 1 1 1 1 -1];

letterF=[-1 1 1 1 1 1 1 1 1 -1; -1 1 1 1 1 1 1 1 1 -1;...
         -1 1 1 -1 -1 -1 -1 -1 -1 -1; -1 1 1 -1 -1 -1 -1 -1 -1 -1;...
         -1 1 1 1 1 1 1 1 1 -1; -1 1 1 1 1 1 1 1 1 -1;...
         -1 1 1 -1 -1 -1 -1 -1 -1 -1; -1 1 1 -1 -1 -1 -1 -1 -1 -1;...
         -1 1 1 -1 -1 -1 -1 -1 -1 -1; -1 1 1 -1 -1 -1 -1 -1 -1 -1];

one=[-1 -1 -1 -1 1 1 -1 -1 -1 -1;-1 -1 -1 -1 1 1 -1 -1 -1 -1;...
     -1 -1 -1 -1 1 1 -1 -1 -1 -1; -1 -1 -1 -1 1 1 -1 -1 -1 -1;...
     -1 -1 -1 -1 1 1 -1 -1 -1 -1; -1 -1 -1 -1 1 1 -1 -1 -1 -1;...
     -1 -1 -1 -1 1 1 -1 -1 -1 -1; -1 -1 -1 -1 1 1 -1 -1 -1 -1;...
     -1 -1 -1 -1 1 1 -1 -1 -1 -1; -1 -1 -1 -1 1 1 -1 -1 -1 -1];
 
two=[-1 1 1 1 1 1 1 1 1 -1;-1 1 1 1 1 1 1 1 1 -1;...
     -1 -1 -1 -1 -1 -1 -1 1 1 -1;-1 -1 -1 -1 -1 -1 -1 1 1 -1;...
     -1 1 1 1 1 1 1 1 1 -1;-1 1 1 1 1 1 1 1 1 -1;...
     -1 1 1 -1 -1 -1 -1 -1 -1 -1;-1 1 1 -1 -1 -1 -1 -1 -1 -1;...
     -1 1 1 1 1 1 1 1 1 -1;-1 1 1 1 1 1 1 1 1 -1];

 %   ----------------------plot standard number figure----------------- 

  LE=imresize(letterE,20);
 subplot(3,4,1)
 imshow(LE)
 title('stand letter')
 
  LF=imresize(letterF,20);
 subplot(3,4,2)
 imshow(LF)
 title('stand letter')
 
  ONE=imresize(one,20);
 subplot(3,4,3)
 imshow(ONE)
 title('stand number')
 
 TWO=imresize(two,20);
 subplot(3,4,4)
 imshow(TWO)
 title('stand number')
 
%  ----------------------create hopfield net--------------------------

 T=[letterE;letterF;one;two]';
 net=newhop(T);
 
 % -----------------------noise array(rand noise)-----------------

            rand('state',0);
            for i=1:10
                for j=1:10
                a=rand;
                if a<0.10
                   letterE(i,j)=-letterE(i,j);
                   letterF(i,j)=-letterF(i,j);
                   one(i,j)=-one(i,j);
                   two(i,j)=-two(i,j);
                end
                end
            end
            no1=letterE;
            no2=letterF;
            no3=one;
            no4=two;
          
 
%  -------------------------plot noisy figure---------------

 subplot(3,4,5)
 NO1=imresize(no1,20);
 imshow(NO1)
 title('noisy letter')
 
 subplot(3,4,6)
 NO2=imresize(no2,20);
 imshow(NO2)
 title('noisy letter')
 
  subplot(3,4,7)
 NO3=imresize(no3,20);
 imshow(NO3)
 title('noisy letter')
 
  subplot(3,4,8)
 NO4=imresize(no4,20);
 imshow(NO4)
 title('noisy letter')
 
 
 
% --------------------------plot identify figure--------------
noise1={(no1)'};
tu1=sim(net,{10,10},{},noise1);
tu1{10}'
subplot(3,4,9)
imshow(imresize(tu1{10}',20))
title('identify number')

noise2={(no2)'};
tu2=sim(net,{10,10},{},noise2);
tu2{10}'
subplot(3,4,10)
imshow(imresize(tu2{10}',20))
title('identify letter')

noise3={(no3)'};
tu3=sim(net,{10,10},{},noise3);
tu3{10}'
subplot(3,4,11)
imshow(imresize(tu3{10}',20))
title('identify letter')

noise4={(no4)'};
tu4=sim(net,{10,10},{},noise4);
tu4{10}'
subplot(3,4,12)
imshow(imresize(tu4{10}',20))
title('identify letter')