"Gabe Schaffer" on wrote...
| On 7/5/06, Peter Valdemar Mørch <[EMAIL PROTECTED]> wrote:
|
| > If I have a tiny crop of a part of an image, how would I find out if
| > that crop is present in the larger image, and if so, the (x,y)
| > coordinates in the larger image, where the crop is to be found?
|
| To do this simply, just write a 2-dimensional string search. Search
| for the first pixel that has the same color as the first pixel in the
| image you're looking for.
|
| Then compare pixels until you either find a
| match or a pixel doesn't match. If the images don't match, start
| searching again at the pixel after the first one you found. This may
| be slow in Perl, unless you dump the image into a Perl array and
| search it that way. Even then it won't be blazingly fast.
|
| To do this quickly in a general purpose way may be a bit of work, but
| for images with few colors, a 2D variant of Boyer-Moore string
| searching would be fast and efficient. Here's an example for searching
| strings:
|
| * Let's say you're looking for the string "ABC". You would build a
| table that would have 0 for A, -1 for B, -2 for C, and 3 for any other
| letter. When searching a string, you would look up the current letter
| in your table and skip ahead however many letters it says. That way
| you would only look at every 3rd letter, backtracking a bit if you
| find a letter that's a B or C, and searching letter-by-letter only if
| you hit an A.
|
| For an image. basically you would build a table that says for any
| color in the image you're searching for, what the minimum X and Y
| distances are to the upper-left. I don't think I have time to write
| such a thing, but it shouldn't be too hard.
|
A Boyer-Moore search would certainally speed things up, but it starts to
fall down when you are 'fuzzy' matching images, say to handle JPEG image
distortions.
Because of the fuzzy matching you can't tabilize the pixels,
However a simular algrothim that should work.
Continuing the problem of 'fuzzy' matching, what is the sub-image you
are tring to locate on the main image only matches up 90% of the pixels?
That is something like...
Location of sub-image that has the best fuzzy match
for maximum number of pixels
For example:
You have an main image with a background tile, and you have another
image which you KNOW is the background tile used on the main image, but
you want to find the offset of that tile on the main image.
Because the forground image could obsure parts background, you may not
find a perfect, unobscured background tile to match against, so the best
match with a extra report on the percentage of pixels that do fuzzy
match, may be the better algorithm.
| > Background: I want to write an app to automate mouse operations in a
| > Windows GUI.
| >
| > I plan to use the perl module Win32::Screenshot that returns an
| > Image::Magick perl object of the desktop and then look for e.g. "the OK
| > button", and then send a mouse click to
| > $screenshot->locationOf($okButtonImage) + (10,10)
|
| If the program you are automating uses standard Windows controls, each
| button will be a window you can find and send a message to. The only
| time you would need something like searching screenshots is if you are
| using a program which draws its own buttons (like a Flash app).
|
The same happens in X Windows under Linux. Which is of course a non-IM
solution.
Anthony Thyssen ( System Programmer ) <[EMAIL PROTECTED]>
-----------------------------------------------------------------------------
Give us this day our daily data,
and forgive us our I/O errors,
as we forgive those whose logic is faulty.
Extract from: http://www.cit.gu.edu.au/~anthony/info/docs/KeyboardPrayer
-----------------------------------------------------------------------------
Anthony's Home is his Castle http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users