⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newway.m

📁 一个用matlab编写的 关于笔画提取的仿真试验程序
💻 M
📖 第 1 页 / 共 2 页
字号:
close all;
clear;
%A2=imread('D:\a实验用\nh1.bmp','bmp');
%figure(9),imshow(A2);
tic;
A1=imread('我.bmp');%%%%  w1/117/a104  qw/126/a157  l2/85/a99   qq/79/a64 yn/78/a75   h2/59/a44 annnew/56/a123 l21
A=rgb2gray(A1);
k=25;
hui=0;
figure(1),imshow(A),title('原字符图像');
[m,n]=size(A);

[Ahen,Ashu]=bihua22(A);
[rowabh]=widthrow(Ashu,m,n);
bb1=mean2(rowabh);
[colabh]=widthcol(Ahen,m,n);
bb2=mean2(colabh);
if bb1>bb2 && bb2>0
    bb=round(bb2);
else 
    bb=round(bb1);
end

[AA2,AA1,CA5,CA7]=bihuafuc(A,m,n);

ath=AA2;

dddd=0;sumt=0;
aaah=ath;%正侧的每列边缘,竖
%figure(32),imshow(ath);
for kkk=1:bb
for    j=1:(n)
for  i=1:(m)
       t1=aaah(i,j);
        if  t1 >0
            dddd=dddd+1;
        elseif  dddd>5
            sumt=dddd;
         dddd=0;
          if A(i,j) >20
             sumt=sumt+1;
             t33=aaah(i-1,j);
          aaah(i,j)=aaah(i-1,j);
          end
       else 
         dddd=0;
      end
        end
end
    end

%figure(33),imshow(aaah);
%%%%%%%%%%%滤波
dd=0;sum1=0;
 for  j=1:(n)
     i=1;
    while(i<=m)
       t1=aaah(i,j);
        if  t1 >0 
          k9=i;
          while aaah(k9,j)>0
              dd=dd+1; 
              k9=k9+1;
              if k9 > m 
                  break;
              end
          end
          if dd <bb/3
              for k8=dd:-1:1;
                  tttt=k9-k8;
                aaah(k9-k8,j)=0;
              end
             i=i+dd-1;
             dd=0;
         else
             sum1=sum1+1;
             startshui(1,sum1)=i;%起始点行坐标
             startshuj(1,sum1)=j;% 起始点列号
             i=i+dd-1;
             endshui(1,sum1)=i;
             endshuj(1,sum1)=j;
        end
        dd=0;
       
    end
     i=i+1;  
 end
end
%%%%%%%%%%%%%%%%
 for i=1:(sum1-1)
     tl1=startshuj(1,i);
     tl2=endshuj(1,i+1);
     tl3=abs(tl1-tl2)+1;
     tl4=(endshui(1,i)+1);
     tl5=(endshui(1,i+1)-1);
        if tl3<=1 
          for j=tl4:tl5
            if A( j ,tl1) >0
                 aaah(j ,tl1)=aaah(j-1 ,tl1);
             end        
         end
     end
 end
 
  %%%%%%滤除小于宽度的竖
  alie=aaah;
  %figure(44),imshow(alie),title('alie竖'); 
 for i=1:sum1
tss=startshui(1,i);
tes=endshui(1,i);
tssj=startshuj(1,i);
tlon=abs(tes-tss)+1;
     if   tlon <(bb)
        for s1=tss:tes
         alie( s1,tssj)=0;
     end
 end
 end
 for i=1:sum1-1
     for j=(i+1):(sum1)
        tss1=startshuj(1,i);
         tss2=startshuj(1,j); 
         tssi1=startshui(1,i);
         tssi2=startshui(1,j);
          tesi1=endshui(1,i);
         tesi2=endshui(1,j);
         tbin=abs(tss1-tss2);
         temp1=0;
         temp2=0;
         temp3=0;
         temp4=0;
          if tbin<=2&&tssi2
             if tssi1 <tssi2
                temp1=tssi1;
                temp3=tssi2;
            else
                temp1=tssi2;
                temp3=tssi1;
            end
             if tesi1 >tesi2
                temp2=tesi1;
                temp4=tesi2;
            else
                temp2=tesi2;
                temp4=tesi1;
            end
            
         end
        if temp1>0 && temp2 > 0&&(temp4>temp1&&temp4>temp3)
            for kc1=temp1:temp2
             alie(kc1,tss1)=255;
             alie(kc1,tss2)=0;
         end
     end
     end
     end
 end

figure(2),imshow(alie),title('alie竖'); 
    %%%%%%%%%%%行补点
aaa=AA1;%负侧的每行边缘
dddd=0;sum2=0;
for kkkk=1:bb
 for  i=1:(m)
    for    j=n:-1:(2)
        
        t1=aaa(i,j);
        if  t1>0
            dddd=dddd+1;
        else
         if  dddd>=bb/2
             dddd=0;
             if A(i,j) >0
               aaa(i,j)=aaa(i,j+1);
              end
          else 
             dddd=0;  
         
     end  
    
       end

end
    end
end

end
%%%%%%%%%%%滤波

dd=0;
 for  i=1:(m)
     j=1;
    while(j<=n)
       t1=aaa(i,j);
        if  t1 >0 
          k9=j;
          while aaa(i,k9)>0
              dd=dd+1; 
              k9=k9+1;
              if k9 > n 
                  k9=k9-1;
                  break;
              end
          end
          if dd < bb 
              for k8=dd:-1:1;
                  tttt=k9-k8;
                aaa(i,k9-k8)=0;
            end
             j=j+dd-1;
             dd=0;
         else
             sum2=sum2+1;
             startheni(1,sum2)=i;%起始点行坐标
             starthenj(1,sum2)=j;% 起始点列号
            j=j+dd-1; 
             endheni(1,sum2)=i;
             endhenj(1,sum2)=j;
        end
        dd=0;
       
    end
     j=j+1;  
 end
  
end

 for i=1:(sum2-1)
     tl1=endheni(1,i);
     tl2=endheni(1,i+1);
     tl3=abs(tl1-tl2);
        if tl3<=1  
            tl4=(endhenj(1,i)+1);
           tl5=(endhenj(1,i+1)-1);
          for j=tl4:tl5
            if A(tl1,j) >0
                 aaa(tl1,j )=aaa(tl1,j-1 );
             end        
         end
     end
 end
 
 
for i=1:sum2
tsh=starthenj(1,i);
teh=endhenj(1,i);
tshi=startheni(1,i);
tlon=abs(teh-tsh)+1;
     if   tlon <bb
        for s1=tsh:teh
         aaah( tshi,s1)=0;
     end
 end
             
 end
ahen=aaa;
figure(3),imshow(ahen),title('ahen横'); 
 %%%%%%%%%%%撇的提取


%figure(4),imshow(na1),title('初捺'); 
 cunna=zeros(m,n);
 na=CA7;
 tnc=0;longn(1,1)=0;
 for  i=1:(m)
     j=1;
    while(j<=n)
        t1=na(i,j);
        kk8=i;kk10=i;
         kk9=j;kk11=j;
        if  t1 >0 
            tb=1; cunna(kk8,kk9)=t1;
          [t2,kk8,kk9]=napos2(na,kk8,kk9);
        while t2>0 && kk9<n && kk8<m
          cunna(kk8,kk9)=t2; 
          na(kk8,kk9)=0;
         [t2,kk8,kk9]=napos2(na,kk8,kk9);
        cunna(kk8,kk9)=t2;
         na(kk8,kk9)=0;
       tb=tb+1;
         end
             if ((double(kk8)-i)==0 && (double(kk9)-j) >10)||((double(kk8)-i)>10 && (double(kk9)-j)==0)
                   for ss=i:kk8
                       for tt=j:kk9
                           na(ss,tt)=0;
                           cunna(ss,tt)=0;
                       end
                   end
               elseif  (abs(double(kk9)-j)+1<=2||abs(double(kk8)-i)+1<=2)||(tb<6&& tb>0)
%                      kk4=i;kk6=kk8;
%                      kk5=j;kk7=kk9;
%                    [t2,na,kk4,kk5]=naclr2(na,kk4,kk5);
%                    while t2>0 && kk4<=kk6 && kk5<=kk7
%                     [t2,na,kk4,kk5]=naclr2(na,kk4,kk5);
%                          end
                   for ss=i:kk8
                       for tt=j:kk9
                           na(ss,tt)=0;
                           cunna(ss,tt)=0;
                       end
                   end 
              
           elseif tb>=6
            tnc=tnc+1;
            hann(1,tnc)=kk8;lien(1,tnc)=kk9;
            hanni(1,tnc)=i;lienj(1,tnc)=j;  longn(1,tnc)=tb;
             
          %            tt2=cunna; figure(112),imshow(tt2),title('.....');  
        else
       
         k=1 ;
     end
            end
            j=j+1;  
      end
  end
   k12=tnc;
  k4=0;
%  figure(108),imshow(cunna),title('a3捺');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -