Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Corner detection and matching is for cases that much more complicate than yours. Your problem is much easier than that. Here number of possible solutions:

Task: Assume that you want to find 100x100 image inside 1000x1000 image. You have 900x900 possible locations of small image. You need to find one location among them where both images will be identical.

Solution 1: Lets start with the most simple and naive way. For each possible location of small image inside big image start comparing pixels. If you find pair of pixels that are different, this location is unacceptable. Stop comparing and move to next possible location. This may sound as bad option because you has 900x900 candidate locations and for each one you need to make up to 100x100 comparisons. But if you are working with natural images you will make only couple of comparisons before discovering that candidate location is wrong. This is because in natural images most pixels are different from each other, so vast majority of candidates will be rejected very fast.

Solution 2: If you are working with artifical images solution 1 is not too good. For example if you are working with binary images you will match lot of pixels before discovering that candidate location should be rejected. In this case you should try to reduce amount of candidate locations. It can be done in many different ways. For example you can check if sum of pixels in candidate region is equal to sum of pixels in small image. Use integral image which implemented in OpenCV to make this comparison in constant time per candidate region.

There many other ways to solve your problem. For example you may calculate Fourier transform of both images, and find location of best correlation between them in frequency space. Not a best option, but option non the less. But don't try compicate solutions before you tried simpler ones.