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

📄 testpipei_2.asv

📁 匹配法对两个图片进行比较
💻 ASV
字号:
function testpipei_2()%基于图象灰度的快速匹配算法

%使用说明:此函数为单独使用,不具有交互性,因此必须在E盘下存在名为:P1010813.jpg的图像,
%在工作区中(此函数所在位置)必须存在名为afterCut.jpg的图像。afterCut.jpg最好是从
%P1010813.jpg的图像上剪裁下来的,P1010813.jpg

yuantu=imread('E:\P1010813.jpg');%加载原图象
pipeitu=imread('afterCut.jpg');%加载匹配图象
yuantu2gray=rgb2gray(yuantu);%将原图象转换为灰度图象
pipeitu2gray=rgb2gray(pipeitu);%将匹配图象转换为灰度图象

[pipei_height,pipei_width]=size(pipeitu2gray);%获取匹配图象的大小尺寸,其值为[长,宽],将匹配图象的长度值赋给pipei_width,将匹配图象的宽度值赋给pipei_lenth

[yuantu_height,yuantu_width]=size(yuantu2gray);%获取原图象的大小尺寸,其值为[长,宽],将原图象的长度值赋给pipei_width,将原图象的宽度值赋给pipei_lenth

temp_min=min([pipei_height,pipei_width]);
temp_min=fix(temp_min/20);
geshu=(temp_min-2)^2;%匹配图R块的个数
fprintf('%d',geshu);
      for t=1:temp_min-2%去掉外围的一圈
       for s=1:temp_min-2%取顺时针为正方向
          temp_pipeitu(t,s)=bin2dec(gettezheng(t,s,pipeitu2gray));
       end;
   end;       
imshow(yuantu);
 hold on;
tic
for i=1:yuantu_height-temp_min*20
    for j=1:yuantu_width-temp_min*20
       temp_picture=imcrop(yuantu2gray,[j,i,pipei_width-1,pipei_height-1]);

       
  %     r=corr2(temp_picture,pipeitu2gray);
       r=0;
   for t=1:temp_min-2%去掉外围的一圈
       for s=1:temp_min-2%取顺时针为正方向
          temp_pipeitu_te=temp_pipeitu(t,s);
          temp_yuantu_te=bin2dec(gettezheng(t,s,temp_picture));
          if temp_pipeitu_te==temp_yuantu_te
             r=r+1;
          else
              break;
          end;
       end;
                
       if r==0
           break;
       end;
   end;
           
         if r>=fix(geshu*0.9)
           plot(j:j+pipei_width,i,'r');
            plot(j:j+pipei_width,i+pipei_height,'r');
            plot(j,i:i+pipei_height,'r');
           plot(j+pipei_width,i:i+pipei_height,'r');
        end
    end
end
toc
       figure;
      imshow(pipeitu);


⌨️ 快捷键说明

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