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

📄 three.m

📁 匹配法对两个图片进行比较
💻 M
字号:

function varargout = three(varargin)
% THREE M-file for three.fig
%      THREE, by itself, creates a new THREE or raises the existing
%      singleton*.
%
%      H = THREE returns the handle to a new THREE or the handle to
%      the existing singleton*.
%
%      THREE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in THREE.M with the given input arguments.
%
%      THREE('Property','Value',...) creates a new THREE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before three_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to three_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help three

% Last Modified by GUIDE v2.5 18-Sep-2007 11:08:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @three_OpeningFcn, ...
                   'gui_OutputFcn',  @three_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before three is made visible.
function three_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to three (see VARARGIN)

% Choose default command line output for three
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes three wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = three_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1
if get(gcbo,'Value')==1;

   
else
    imformats;
end

% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function openPicture_Callback(hObject, eventdata, handles)
% hObject    handle to openPicture (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  
    global public_A;
    global pname;
    global adrname;

    
   [pname,adrname]=uigetfile('*.jpg','*.bmp');
   if exist(strcat(adrname,pname))
   public_A=imread(strcat(adrname,pname));
   axes(handles.axes1);   % 在指定的坐标显示图像
   imshow(public_A);
   else
       return;
   end;
   
% --------------------------------------------------------------------
function close_Callback(hObject, eventdata, handles)
% hObject    handle to close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 close all;

% --- Executes on button press in nishizhen.
function nishizhen_Callback(hObject, eventdata, handles)
% hObject    handle to nishizhen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 global public_A;
public_A=imrotate(public_A,90);
axes(handles.axes1);   % 在指定的坐标显示图像
imshow(public_A);


% --- Executes on button press in shunshizhen.
function shunshizhen_Callback(hObject, eventdata, handles)
% hObject    handle to shunshizhen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global public_A;
public_A=imrotate(public_A,-90);
axes(handles.axes1);   % 在指定的坐标显示图像
imshow(public_A);



% --- Executes on button press in cut.
function cut_Callback(hObject, eventdata, handles)
% hObject    handle to cut (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global public_A;
global public_B;

public_B=imcrop(public_A);
axes(handles.axes3);   % 在指定的坐标显示图像
imshow(public_B);



% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in huidu.
function huidu_Callback(hObject, eventdata, handles)
% hObject    handle to huidu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global public_A;
public_A=rgb2gray(public_A);
imshow(public_A);



% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
   global public_A;
    global pname;
    global adrname;
[temp_pname,temp_adrname]=uiputfile(strcat(adrname,pname),'保存图象');
imwrite(public_A,strcat(adrname,pname));

% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject    handle to close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in openduibi.
function openduibi_Callback(hObject, eventdata, handles)
% hObject    handle to openduibi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    global public_A;
    global pname;
    global adrname;
    global public_B;
    
   [pname,adrname]=uigetfile('*.jpg','*.bmp');
   if exist(strcat(adrname,pname))
   public_B=imread(strcat(adrname,pname));
   axes(handles.axes3);   % 在指定的坐标显示图像
   imshow(public_B);
   else 
       return;
   end;
   
% --- Executes on button press in pipei_1.
function pipei_1_Callback(hObject, eventdata, handles)
% hObject    handle to pipei_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    global public_A;
    global pname;
    global adrname;
    global public_B;
    
   axes(handles.axes1);   % 在指定的坐标显示图像
   hold off;
   imshow(public_A);
    
yuantu2gray=rgb2gray(public_A);%将原图象转换为灰度图象
pipeitu2gray=rgb2gray(public_B);%将匹配图象转换为灰度图象

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

[yuantu_height,yuantu_width]=size(yuantu2gray);%获取原图象的大小尺寸,其值为[长,宽],将原图象的长度值赋给pipei_width,将原图象的宽度值赋给pipei_lenth
   axes(handles.axes1);   % 在指定的坐标显示图像
   imshow(public_A);
   hold on;
for i=1:yuantu_height-pipei_height
    for j=1:yuantu_width-pipei_width
       temp_picture=imcrop(yuantu2gray,[j,i,pipei_width-1,pipei_height-1]);
       
       r=corr2(temp_picture,pipeitu2gray);

         if r>0.98
           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




% --- Executes on button press in pipei2.
function pipei2_Callback(hObject, eventdata, handles)
% hObject    handle to pipei2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
   axes(handles.axes1);   % 在指定的坐标显示图像
   global public_A;
   global public_B; 
   global pname;
   global adrname;
   hold off;
   imshow(public_A);
  
%基于图象灰度的快速匹配算法
    
yuantu2gray=rgb2gray(public_A);%将原图象转换为灰度图象
pipeitu2gray=rgb2gray(public_B);%将匹配图象转换为灰度图象

[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]);
k=fix(temp_min/5);


      for t=1:3%去掉外围的一圈
       for s=1:3%取顺时针为正方向
          temp_pipeitu(t,s)=bin2dec(gettezheng(t,s,pipeitu2gray,k));
          
       end;
   end;       
   axes(handles.axes1);   % 在指定的坐标显示图像
   imshow(public_A);
   hold on;

for i=1:yuantu_height-5*k
    for j=1:yuantu_width-5*k
       temp_picture=imcrop(yuantu2gray,[j,i,pipei_width-1,pipei_height-1]);
       
       r=0;
   for t=1:3%去掉外围的一圈
       for s=1:3%取顺时针为正方向
          temp_pipeitu_te=temp_pipeitu(t,s);
          temp_yuantu_te=bin2dec(gettezheng(t,s,temp_picture,k));
          if temp_pipeitu_te==temp_yuantu_te
             r=r+1;
          else
              break;
          end;
       end;
                
       if r==0
           break;
       end;
   end;   
         if r>=8
           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
 



⌨️ 快捷键说明

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