CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    2

    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.

  2. #2
    Join Date
    Nov 2012
    Posts
    2

    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;
    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).

  3. #3
    Join Date
    Feb 2012
    Location
    Fremont,CA
    Posts
    37

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured