# I have small image and big image. How i can search small image on big image and get

• November 18th, 2012, 12:29 PM
lapdx
I have small image and big image. How i can search small image on big image and get
I have small image and big image. How i can search small image on big image and get x,y coords of small image?
Give mr,pplease, examples for get solution. I search this info at long time.
• November 20th, 2012, 03:36 AM
lapdx
Re: I have small image and big image. How i can search small image on big image and
Simple way: iterate over all possible positions of the small image in the big image and see how well the small image matches at that position. Evaluating the match requires iterating over all pixel positions in the small image. The resulting loop looks something like this:
Code:
double best_score = HUGE_VAL;
Quote:

for (int y = 0; y + small_h <= big_h; ++y) {
for (int x = 0; x + small_w <= big_w; ++x) {
double score = 0;
for (int s = 0; s < small_h; ++s) {
for (int r = 0; r < small_w; ++r) {
double diff = small_image[s][r] - big_image[x+s][y+r];
score += diff*diff;
}
}
if (score < best_score) {
best_score = score;
// Also keep track of the matching position here
}
}
}
How well this works depends on how good the "match" really is. If it's a near-exact match, then you'll almost surely find it, but life is more complicated if the match is just approximate (for example, if you're trying to match one photograph to a different photograph). This fuzzy version of the problem is still a topic of active research, but I think there are various implementations in some popular image processing and computer vision libraries (like OpenCV).

One other thing I should point out is that if you decide to use the simple computation and the images in question are sufficiently large, and especially if the small image is not very small, it can pay to go through the Fourier domain rather than directly implementing the four-level nested loop. If you don't know what I'm talking about, then I'm afraid I can't explain it in a forum post; you should just do it the simple way or find an existing implementation (or learn about the Fourier transform and convolutions).
• November 22nd, 2012, 11:27 PM
kevin619
Re: I have small image and big image. How i can search small image on big image and
What is the format of the image? BMP, JPG, GIF TIF PNG etc.