Object Recognition using Correlation

Individual Project


While taking a course on Discrete Time Signals and Systems at college, I completed the following project as a part of the curriculum. In this project an image is taken and a template is cropped out of it. Then correlation is performed using Fourier transform and the locations where the templates match has a higher pixel value. Then we define a threshold which is used to separate these high pixel value locations from the rest of the image and thus we get locations of the template on the image.

This technique of character recognition has some drawbacks though. The most prominent of them being, that the template image must be a near match to the objects in the image. Thus when parsing documents for handwritten text, this technique does not give the required results (I have tried this, and it failed to give a reliable result). The second drawback being that the threshold although can be taken as a value just lower than the maximum pixel value. But this usually has to be set by the programmer as the automated procedure doesn’t always gives the desired result. The problem also multiplies when you move from black and white images to color images.

This project was designed in MATLAB R2011b. I have attached the codes and results of the same at the end of this post.

Technical Description:

The Fourier transform can also be used to perform correlation. Following are the steps while matching a template to the image using the above said procedure.

  1. Read in the sample image.
  2. Create a template for matching by extracting it from the image. You can also create the template image by using the interactive version of imcrop.
  3. Compute the correlation of the template image with the original image by rotating the template image by 180oand then using the FFT-based convolution technique. To match the template to the image, use the fft2and ifft2 functions. This technique was described on a forum on MathWorks and greatly helped in understanding the functions.

C = real(ifft2(fft2(bw) .* fft2(rot90(a,2),256,256)));

  1. To view the locations of the template in the image, find the maximum pixel value and then define a threshold value that is less than this maximum. The locations of these peaks are indicated by the white spots in the thresholded correlation image.

Here is a link to the zip folder containing the MATLAB files and images I had used in this project. Project 1. Project 2.

Leave a Reply

Your email address will not be published. Required fields are marked *