search for subimage and replace

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bongo
Posts: 2
Joined: 2011-03-22T08:34:33-07:00
Authentication code: 8675308

search for subimage and replace

Post by bongo »

i would like to search a big image for all occureces of a smaller subimage and mark these positions.

using -subimage-search, i always just get one position of the subimage marked within the big image ;-(
there also should be a way to define a matching tolerance, as there will be some differences between the subimage and the occurences within the big image because of compression.

i would like to get all occurences of the subimage colored (or maybe marked in any other way) within the big image.

how can this be done?

thanx!
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: search for subimage and replace

Post by whugemann »

I think http://www.wizards-toolkit.org/discours ... =3&t=20426 demonstrates what you are looking for. AFAIK, you can only search for the first location of a subimage. Therefore you must perfrom your task in a loop, i.e. search for the first occurance, store its location, blank that area, store an interim image, search for the first occurance in that interim image, and so on, until the image cannot be found any more.

After that loop is finished, you can use your stored values to manipulate the original image, e.g. draw rectangles around that areas or alike. The processing will be very slow, though.

If I were you, I would look whether there is a ready-made plugin for Fiji performing this task, which I think is quite likely.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: search for subimage and replace

Post by fmw42 »

If you are on unix or windows with cygwin, you can process the second (match score) image from the compare of a small image with a larger one to find other matches using my bash unix script, maxima. See the link below.
Last edited by fmw42 on 2012-03-28T19:59:03-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: search for subimage and replace

Post by anthony »

bongo wrote:i would like to search a big image for all occureces of a smaller subimage and mark these positions.

using -subimage-search, i always just get one position of the subimage marked within the big image ;-(
there also should be a way to define a matching tolerance, as there will be some differences between the subimage and the occurences within the big image because of compression.

i would like to get all occurences of the subimage colored (or maybe marked in any other way) within the big image.

how can this be done?

thanx!
Typically the map of matches, is further processed to highligh and locate 'peaks' within the image
This can be done using Speciallized Morphology or Convolution Kernels
One example is in...
http://www.imagemagick.org/Usage/convol ... ate_search


If you can give a small sample image (the image searched, and the sub-image to look for), we can help further.
Though I remember a specific 'mandrill eyes' image that Fred has used to find BOTH eyes.
Hmm yes.. From Fred's Maxima Script
http://www.fmwconcepts.com/imagemagick/maxima/index.php

This masks out findings (to remove any other nearby peak) until some limit is reached.
However with one preprocessing step using a morphology 'peaks' kernel
http://www.imagemagick.org/Usage/morphology/#peaks
you can highlight and discount all 'nearby' peaks in the one step. The result can be used as a mask into the original image to find the actual 'peak' value at that point, rather than the 'difference' gap


I have updated my notes about methods of peak finding... (give it an hour or so)
http://www.imagemagick.org/Usage/compare/#peak_finding
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply