Page 1 of 1

Match Then Crop

Posted: 2015-04-19T17:26:09-07:00
by afre
Hello All, I used a script to detect and crop a set of objects, but it isn't color managed and resizes the input. I would like to take the output, find their location in the originals and then crop to get a more accurate set. Unsure whether that's the best approach but it's a start.

I've tried using this but it doesn't work. (Maybe my test original is too large.) fmw42 also has a bunch of scripts, DOTPRODUCTCORR NORMCROSSCORR PHASECORR RMSECORR, but I don't know which one is suitable for the task. I am sure that each has it's application.

Re: Match Then Crop

Posted: 2015-04-19T17:36:40-07:00
by fmw42
Please always provide your IM version and platform.

IM has the compare function, which can be very slow on large images. The syntax is:

Code: Select all

compare -metric rmse -subimage-search largeimage smallimage null:
You can choose another metric if you want, but I typically use rmse. The output will provide the match error score (smaller is better) and the top left (offset) coordinates in the large image where to start your crop of the same size as the small image.

But this function is neither scale nor rotationally invariant. There must only be a shift difference between the two (though the brightness/contrast may be somewhat different).

If on unix, you may try my script such as normcrosscorr, but then you must compile IM in HDRI mode and have installed FFTW delegate library.

See the following for examples, but in the first, you will need to add -subimage-search, since that has been added since the example was created.

viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr

Re: Match Then Crop

Posted: 2015-04-19T19:13:14-07:00
by afre
fmw42 wrote:But this function is neither scale nor rotationally invariant.
Are your scripts invariant as well? Maybe I'll try something else (and smaller images). Thanks anyway.

Re: Match Then Crop

Posted: 2015-04-19T21:06:07-07:00
by fmw42
My scripts have the same limitation -- not scale or rotationally invariant. But they run much faster than compare.

Perhaps you should post an example pair of images (not huge ones), so we can see what you are trying to do. You can upload them to someplace such as dropbox.com and put the URLs here.

For rotational invariance, perhaps see viewtopic.php?f=2&t=26530