#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    How i can search small image on big image and get x,y coords of small image?


    How i can search small image on big image and get x,y coords of small image?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    186
    Rep Power
    82
    Originally Posted by lapdx
    How i can search small image on big image and get x,y coords of small image?
    What is the format of the image? BMP, JPG, GIF TIF PNG etc.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    JPG - format.

    Well. We have big image. We want search coords of small image. Small image be in big image.

    c++
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    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).
  10. #6
  11. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    I have a good friend who recently took classes on image analysis and while there are some basic ways to do analysis, anything 'simple' is seldom realized in the real world and getting something useful entails a massive number of tradeoffs, not the least of which is performance. These sorts of algorithms tend to be highly compute bound and sometimes are very difficult to multi-thread (and see a performance gain). I think, unless you have a highly specific application and are prepared to dive into the math and algorithms, you are way better served by learning to use a package (such as the afore mentioned OpenCV).

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0
    There two ways to interpret what you are asking for (that i can think of):
    1) Pixel by pixel comparison.
    2) High-level artificial intelligence comparison.

    The first one is much easier but not easy. The basic idea is to loop through the large imageís pixel and check for matches with smaller image and if yes, check the next pixel. Personally, instead of implementing my own algorithm, I check libraries that had this already. I used an sdk called leadtools to do this and it gave me good results. Of course pixel by pixel comparison is not a fast process so the performance was a little slower than expected.
    As for the second option, I havenít personally tried it but it will be hard to implement.
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Great to have a new poster!
    Welcome.

    The new threads have current relevance. Usually work with them.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo