C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 19th, 2012, 03:14 PM
lapdx lapdx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 lapdx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 42 sec
Reputation 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?

Reply With Quote
  #2  
Old November 19th, 2012, 04:26 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old November 19th, 2012, 07:34 PM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 118 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 h 48 m 29 sec
Reputation Power: 44
Quote:
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.

Reply With Quote
  #4  
Old November 20th, 2012, 01:29 AM
lapdx lapdx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 lapdx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 42 sec
Reputation Power: 0
JPG - format.

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

c++

Reply With Quote
  #5  
Old November 20th, 2012, 02:50 AM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
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).

Reply With Quote
  #6  
Old November 20th, 2012, 04:59 AM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How i can search small image on big image and get x,y coords of small image?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap