Code covered by the BSD License  

Highlights from
Image correspondences using cross-correlation

5.0

5.0 | 5 ratings Rate this file 80 Downloads (last 30 days) File Size: 764 KB File ID: #27269
image thumbnail

Image correspondences using cross-correlation

by

 

16 Apr 2010 (Updated )

Find matching features in pairs of images using normalised cross-correlation: class file and demo.

| Watch this File

File Information
Description

Finding corresponding features in a pair of images is the basis of many optic flow, stereo vision and image registration algorithms. One straightforward approach to finding a match is to take a small patch of one image, compute its sliding cross-correlation with the other image, and find a peak. This submission supplies a class which implements this method.

There are many other ways of finding correspondences, but normalised cross-correlation is relatively easy to understand, and fairly effective if a sparse set of matches is sufficient and the change in viewpoint is not too large. This submission is intended largely as a learning aid, though it may be usable for some applications. A demonstration script is therefore included.

The algorithm extends the basic idea in two ways. First, a reverse match may be done on each feature pair to test for consistency; this eliminates many incorrect matches. Second, the correlation computation may be greatly speeded up using the SVD trick implemented in convolve2, at the cost of some accuracy and density of matches.

The core of the submission is object-oriented to facilitate its use with image sequences and to allow efficient reuse of parts of the computation.

Acknowledgements

Fast 2 D Convolution and Extended Array Indexing inspired this file.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
05 Jun 2014 David Young

sush: Maybe you have a file called edge.m on your path that is hiding the toolbox edge function. What is the output of the command "which edge"? If the result isn't in the Image Processing Toolbox, you could try renaming your edge.m file.

05 Jun 2014 sush

its showing error dat "attemp to call edge as script function " why ? ?

21 Oct 2013 MD JAYED Hussan  
18 Oct 2013 David Young

farah: Yes, you can use another set of images. You'll see that the images are read from disk at the start of the demo, and you can change those lines to read different images. However, it will be better in the end to write your own code to call correlCorresp rather than relying on the demo. If you are not sure how to proceed, you may need to work through "Getting Started with Matlab" in the documentation.

MD JAYED Hussan: The corresponding coordinates are held in the corresps property of a correlCorresp object, after a call to the findCorresps method. You can see how the vectors are computed by inspecting the code for correspDisplay. It's all in the documentation, by the way.

18 Oct 2013 MD JAYED Hussan

The code is working great. Can point me where i need to modify it to get the length of the blue lines so that i have calculate the velocity of shifting between two slides when i have a frame rate.

17 Oct 2013 farah

cant I use another set of Images ?If yes then what change is required in which part of the code

18 Jun 2013 David Young

katia - sorry not to get back sooner. I hope you've solved the problem by now. It's easy - just look at the code that does the display for the demo and modify it to do what you want.

12 Sep 2012 katia subeva

Is there any way to display the feature points in every one of the two images before showing the correspondence between them?

27 Nov 2011 Garry  
30 Jun 2011 Lyuboslav  
16 Feb 2011 David Young

vamsi - It is possible to get an intermediate view using these correspondences, but how successful it will be depends on the complexity of the flow field. Extending the demo in the FEX package, you can do something like this:

x1 = cc.corresps(1,:);
y1 = cc.corresps(2,:);
x2 = cc.corresps(3,:);
y2 = cc.corresps(4,:);
input_points = [x1' y1'];
base_points = [(x1+x2)' (y1+y2)']/2; % half way between matchine features
% Generate transform from image1 to half-way position
tform = cp2tform(input_points, base_points, 'piecewise linear');
% Apply it to image 1
interp = imtransform(image1, tform, 'Xdata', [1 size(image1,2)], 'Ydata', [1 size(image1,1)]);

to get an image intermediate between the two images. I've found that for complex flow fields a piecewise linear transform can't be found, but the lwm option can work. I can't make a recommendation though - you have to experiment with your own data set.

15 Feb 2011 vamsi

david-I am trying to get an intermediate view between these two images with out disparity map. So i need to know the amount by which each pixel has been moved. Can i go for image morphing with these available sparse set? In such a case, which morphing technique would you suggest..

15 Feb 2011 David Young

vamsi - I'm glad it's helpful. I am sorry, but I don't know the best way to make a dense set - that's a difficult problem, and there's a lot of research literature to look at. Interpolation is not good because the flow field is discontinuous, and so it's necessary to go back to the original images to do segmentation. Sorry not to be more help, but it's a big question.

14 Feb 2011 vamsi

Hi david. Thankyou so mcuh for this work. It really helped me a lot. After getting the correspondences, how can i make it dense set from the sparse set obtained. I tried some interpolation techniques. But they did not worked. Please help me

26 May 2010 David Young

Marco - It's necessary to convert rgb images to greyscale (using rgb2gray).

25 May 2010 Marco Marienberg

David - So what was the resolution since I'm getting the same errors that Michael did. I am running 7.9.0 (R2009b).

24 May 2010 David Young

Note to potential users: the issue identified by Michael was resolved between us - there isn't a problem with the code.

09 May 2010 David Young

That's puzzling! What does "which conv2 -all" print?

08 May 2010 Michael Coughlin

Hi again,

Forward matches: ??? Undefined function or method 'conv2' for input arguments of
type 'double'
and attributes 'full 3d real'.

Error in ==> convolve2>doconv at 95
y = conv2(conv2(x, u(:,1)*s(1), shape), vp(1,:), shape);

Error in ==> convolve2 at 71
y = doconv(x, m, shape, tol);

Error in ==> patch_var at 29
a = convolve2(x, m, shape);

Error in ==> varPeaks at 17
vars = patch_var(im, patchsize);

Error in ==> correlCorresp.correlCorresp>correlCorresp.findFeatures at 466
[r, c] = varPeaks(cc.im1, cc.fPS, cc.rT);

Error in ==> correlCorresp.correlCorresp>correlCorresp.findCorrespsFwd at 545
cc = cc.findFeatures;

Error in ==> correlCorresp.correlCorresp>correlCorresp.findCorresps at 489
cc = cc.findCorrespsFwd;

Error in ==> correspDemo_1 at 38
cc = cc.findCorresps;

>> conv2
??? Error using ==> conv2
Not enough input arguments.

So I see conv2 but it does not seem to like it, might you know why?

Michael

08 May 2010 Michael Coughlin

Ah silly me. 2010a, right above. I will give that a go and see how if that fixes it.

08 May 2010 David Young

Hi Michael,

I'm not sure what the problem is, but I wonder if it's a version problem - what version of Matlab are you using?

You don't need to put the files in a special "@" directory - they just go in a folder on your path as normal. But I don't think that in itself would cause the error you observe.

David

08 May 2010 Michael Coughlin

Hi David,

So I am a little new to class definitions in Matlab, but I placed correlCorresp.m in a folder @correlCorresp and modified the demo to include 2 of my .png files.

>> correspDemo_1
??? Error: File: /mnt/qfs4/mcoughlin/IM/daily/2010_05_01/plots/crossCorr/@correl
Corresp/correlCorresp.m Line: 190 Column: 28
Undefined function or variable 'private'.

Error in ==> correspDemo_1 at 24
cc = correlCorresp('image1', image1, 'image2', image2, 'printProgress', 100);

So that means it is complaining about this line:
properties (Dependent, SetAccess = private)

Do you happen to know what I am doing incorrectly?

Thank you for your help,
Michael

29 Apr 2010 David Young

Thanks, Ulrich. I don't have a publication on this code, so no real reference, though the SVD trick that speeds up the correlations is described here: 'Computer and Robot Vision' Vol I, by R.M. Haralick and L.G. Shapiro (Addison-Wesley 1992), pp. 298-299.

Subpixel displacements: yes, I've been thinking about this, but I haven't done it yet.

28 Apr 2010 Ulrich

Wow, this is great. I'm trying to get similar results for landslide displacements using DEMs quite some time now. And this is faster, more reliably and gave me results straight ahead. Thanks for this. Now I have to modify it a bit for subpixel displacements. The reverse matching sort out nicely mismatches in my case. Is there any reference I can use when I include this in my thesis?

Updates
19 Apr 2010

Code tidied; demo extended.

21 May 2010

Revised the properties that control user-specified feature locations and propagation of features in image sequences.

09 Dec 2011

Minor updates to comments. Update to method used by findpeaks, which now calls imregionalmax.

Contact us