## Is there any robust solution to match two images and find the percentage of match between them in MATLAB ?

### meghna bhatt (view profile)

on 15 Jul 2013
Latest activity Commented on by Walter Roberson

on 28 Aug 2016

### Alex Taylor (view profile)

Problem description -

->say we already have some no of template(base) images in one folder

Input -

`    - Image to find its perfect matching image`

Output -

`    -Matched Image (if found)`
`    -Otherwise Message - no matching found `

I need robust solution to this ..

I have tried using SURF Features but its not giving me robust output meaning it sometimes gives wrong match - though it its giving quite good result but not 100 %

Here is the rough logic of my current algorithm :

` Input_Image_gray = rgb2gray(Input_Image);`
` Input_keys = detectSURFFeatures(Input_Image_gray);`
` [Input_features Input_validPts] = extractFeatures(Input_Image_gray,  Input_keys);`

----iterate for loop for the Template images we have in a Folder

` templateImage=templateImagesArray{loopCounter};`
` ref_img_gray = rgb2gray(templateImage);`
` ref_keys=detectSURFFeatures(ref_img_gray);`
` [~, MATCH_METRIC] = matchFeatures(ref_features,Input_features  ,'MatchThreshold',3);`

-- Calculate percentage for each image on the base of MATCH_MATRIC

` if percentage > 50`
`    display the matched Image`
`    otherwise display message -  no matching image fond`

----end loop

please share if any body has any idea regarding how to achieve this

### Alex Taylor (view profile)

on 15 Jul 2013

When solving registration problems, there is typically not any one algorithm that will be robust 100% of the time. That said, you may find that you can achieve very good results with a particular dataset if you choose your algorithm appropriately.

As far as which algorithm to use, you should consider the following questions:

1) What types of geometric deformations do you expect are present in your data? 2) Do the images in your dataset have strong features in terms of Corners, SURF features, etc. 3) Are all the images in your dataset collected with a similar sensor? 4) Are all of the images in your dataset illuminated the same?

You have mentioned already that there is skew present in your images. The presence of shear means that you require an affine model to solve the registration.

You will not be able to use normxcorr2, because there is no known correlation based approach for resolving shear.

If you are getting good results with feature based approach using SURF and estimateGeometricTransform in CVST, I would see if you can tune the feature matching and RANSAC steps to get the kind of robustness you are looking for. SURF is an appropriate algorithm for solving affine registration problems.

meghna bhatt

### meghna bhatt (view profile)

on 16 Jul 2013

I think your approach is good and I am already using SURF option

I also think SURF will be best suited for my requirements

answers of the questions you just specified are :

let me explain

1)Yes My input data will have its quality deformed and distorted some time as the medium is scanner to capture the form

2)Yes Images in Dataset has not that much strong features that are identical compare to others

3)No all the images in my dataset collected are either of Scanner or Camera Captured Images

4)Any extra illumination does not applied on the image but in case of camera captured image it will be there in different variation

Here only issue is result should be Accurate - means if not matched then algorithm should be able to tell that there is no match found rather giving the wrong matched image

meghna bhatt

### meghna bhatt (view profile)

on 16 Jul 2013

Hey , My another problem is performance

When I am using SURF Method and matchFeatures it is taking huge time to give output

I found the two internal methods of MATLAB which are bottlenecks for slow performance through profiler

cvalgMatchFeatures>metricSSD repmat

why these are taking so much time?if any body knows please share...

### Image Analyst (view profile)

on 15 Jul 2013

If you're searching for a "perfect matching image" simply subtract the two images:

```diffImage = double(image1) - double(image2);
perfectMatch = (sum(diffImage(:)) == 0);
```

You can use nnz if you want to find the percentage that aren't the very same pixel value. Only use SURF if you want to compare approximate matches, not exact matches.

Show 1 older comment
Image Analyst

### Image Analyst (view profile)

on 15 Jul 2013

Then it's not perfect, it's approximate like I said. You can use normxcorr2() if you want to find out where and if a smaller template image appears in a larger image. Or you can use SURF, like they use often in CBIR. Or look to other sophisticated cbir methods.

Walter Roberson

on 28 Aug 2016

Walter Roberson

### Walter Roberson (view profile)

on 28 Aug 2016

ahmed SHAH, please clarify what you need assistance with.