No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Picture Matching Function

3.5 | 15 ratings Rate this file 21 Downloads (last 30 days) File Size: 1.12 KB File ID: #5456 Version: 1.0

Picture Matching Function



11 Jul 2004 (Updated )

Matches two pictures given as arguments.

| Watch this File

File Information

The function takes two images as argument and using edge detection checks whether they are the same or not...a cool and simple code which can be used in security systems. The level at which the two pictures should be matched can be controlled.

Required Products Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (20)
01 Nov 2016 vinay kumar ega

28 Mar 2014 NICK

NICK (view profile)

@joao Soares : I tried ur code but m getting the foll. error-
Error using ait_picmatch1 (line 3)
Not enough input arguments.

Can any1 plz help me with this.

Comment only
12 Nov 2012 piyush kant

What so ever about the size.
It gives a brief idea about matching algorithm.
good work.

18 Feb 2012 Josué Dread

Sorry, I'm new at matching images and using Matlab, can you helpme telling me how to show the matched image??

Comment only
22 Nov 2011 Ali Tayeh

there is many errors

Comment only
31 May 2008 menna gaber


Comment only
04 Mar 2008 Indrachapa Bnadara

Good programme

19 Jan 2008 Xz Xz

austin karathra, yes it's ravings of a madman.Very simple realization, work only with identical picrures!!!

22 Dec 2007 z lijie

Recently ,I'm looking for the code almost everywhere and finally I'm very lucky to find it here.thankyou!Fahd Ahmad Abbasi

11 Dec 2007 austin karathra

This is not working and again this algorithm will not work if the images are shifted by a pixel.
need some modifications

17 Jul 2007 venkatesh Deva


19 May 2007 Addison Tsui

Use the im2bw() function with a threshold in the code would provide a more clear comparison of the images.

14 Dec 2006 Noman Shaukat

A bit of noise destroys the whole process .
Even does not works for a threshold percentage of 40% and applications of filters. (I am working on TV captures). A preferred method would be to go for corners instead of edges. and do feature correspondance or Instead of relying on edges or corners go for cross correlation.
Process would be expensive, but the desired match quality would be there.

27 Sep 2006 x zeng

joao Soares:nice work!
Thanks Fahd Ahmad Abbasi also.

Comment only


01 May 2006 loony tones

08 Jan 2006 joao Soares

The code is terribly inneficient, only works if the images are taken under the same conditions! try to compare 2 diferent pictures taken to the same object, the ratio will be very low... I´ve improved you code :

function ait_picmatch(pic1,pic2)

[x1,y1,z1] = size(pic1);
pic1 = rgb2gray(pic1);

[x2,y2,z2] = size(pic2);
pic2 = rgb2gray(pic2);

%applying edge detection on first picture
%so that we obtain white and black points and edges of the objects present
%in the picture.

edge_det_pic1 = edge(pic1,'prewitt');

%%applying edge detection on second picture
%so that we obtain white and black points and edges of the objects present
%in the picture.

edge_det_pic2 = edge(pic2,'prewitt');

%definition of different variables to be used in the code below

%output variable if pictures have been matched.
OUTPUT_MESSAGE = ' Hence the pictures have been matched, SAME PICTURES ';

%output variable if objects in the whole picture have not been matched.
OUTPUT_MESSAGE2 = ' Hence the pictures have not been matched, DIFFERENT PICTURES ';

%initialization of different variables used
matched_data = 0;
white_points = 0;
black_points = 0;

%for loop used for detecting black and white points in the picture.
for a = 1:1:x1
for b = 1:1:y1
white_points = white_points+1;
black_points = black_points+1;

%for loop comparing the white (edge points) in the two pictures
for i = 1:1:x1
for j = 1:1:y1
matched_data = matched_data+1;

%calculating percentage matching.
total_data = white_points;
total_matched_percentage = (matched_data/total_data)*100;

%outputting the result of the system.
if(total_matched_percentage >= 90) %can add flexability at this point by reducing the amount of matching.



This code only works for images with the same size, but the size is now variable!

12 Sep 2005 Bob Floogerman

Very simple code, easy to use AND scale- could easily be modified for images of any size, and it's easy to adjust the tolerance (percentage) of comparison. Too bad this is dependent on matlab, and not a library for PHP, ASP, or some other unversal scripting language.

14 Apr 2005 Janik Zikovsky

Will not handle sizes other than 256x256, inefficient unvectorized code.

17 Dec 2004 Hamid Mukhtar

Contact us