It depends if you are doing an “exact” match with bit patterns or just an approximate (fuzzy) match for images. If you're doing exact matching, just treat the bitmaps as a general search for an array of 2D data.
The smallest but very simple implementation for exact matching can be done in N * M, where N is the number of pixels in the haystack, and M is the number of pixels in the needle.
Given that Haystack is the size (S, T) and the needle bit is the size (U, V), you can iterate over the Haystack using X = [0, SU) and Y = [0, TV). For each location, you can look at a 2D sub-array of the same size as Needle [{X, Y}, {X + U, Y + V}) and compare it with the needle [{0,0}, {U , V}).
source
share