i have two bitmaps in code (.NET). I’d like to search for the small pattern (needle) in the big image (haystack). How can this be done?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends if you are doing an “exact” match with bitwise patterns or just an approximate (fuzzy) image match. If you are doing an exact match simply treat the bitmaps as a generic 2D data array search.
A naive but very easy implementation for the exact match can be made in N*M time where N is the number of pixels in the haystack and M is the number of pixels in the Needle.
Given the Haystack is size (S,T) and the Needle Bitmap is size (U,V), you can iterate over Haystack with X=[0,S-U) & Y=[0,T-V). For each location, you can look at a 2D sub-array the same size as the Needle [{X,Y},{X+U,Y+V}) and compare it to the Needle [{0,0},{U,V}) coordinates.