compare -subimage-search very slow since 6.6.6-0

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Hobbes
Posts: 2
Joined: 2011-09-21T04:06:44-07:00
Authentication code: 8675308

compare -subimage-search very slow since 6.6.6-0

Post by Hobbes »

I am not really sure if it is a bug or a sideeffect of a new feature, so please be lenient with me if this is the wrong board.

With IM 6.6.5-3-q16-windows, the search for a subimage of 43x23 pixels in a 700x480 pixel image takes about 3-4 seconds on my pc. With IM
6.6.6-0-Q16-windows and IM 6.7.2-7-q16-windows the same job takes about 68 seconds. Of course, the pc, the images and the commandline
parameters are the same in all cases:
compare -metric AE -subimage-search part.png image.png null

I already looked into the change history from 6.6.5-3 to 6.6.6-0, but I did not find a hint on a change introducing
a new feature or a bugfix for this topic.

Crosscheck with another machine was also done with the same results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compare -subimage-search very slow since 6.6.6-0

Post by fmw42 »

Hobbes wrote:I am not really sure if it is a bug or a sideeffect of a new feature, so please be lenient with me if this is the wrong board.

With IM 6.6.5-3-q16-windows, the search for a subimage of 43x23 pixels in a 700x480 pixel image takes about 3-4 seconds on my pc. With IM
6.6.6-0-Q16-windows and IM 6.7.2-7-q16-windows the same job takes about 68 seconds. Of course, the pc, the images and the commandline
parameters are the same in all cases:
compare -metric AE -subimage-search part.png image.png null

I already looked into the change history from 6.6.5-3 to 6.6.6-0, but I did not find a hint on a change introducing
a new feature or a bugfix for this topic.

Crosscheck with another machine was also done with the same results.
I don't think subimage search feature of compare has ever been 3-4 sec for those sizes. The only way it could have been 3-4 seconds if you were comparing two equal sized images.

Also your syntax is incorrect. The larger image must be first and null must have : after it as null:

However, it does seem excessively slow:

time compare -metric AE -subimage-search logo: logo_center50x50.png null:

where the small image was 50x50 center of the logo: image

and quit it after 16 minutes!

Using IM 6.7.2.7 Q16 Mac OSX Tiger on old PowerPC G4 Mac Mini 512 Mbytes memory.

Whereas, when I ran this test at viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076 it did finish after 45 seconds. The large image was 256x256 and the small image was 23x14


time compare -metric rmse -subimage-search mandril3.png mandril3_156_22.png null:
0 (0) @ 156,22

real 0m45.051s
user 0m39.868s
sys 0m0.672s


I imagine the time goes way up as the size of the subimage gets bigger.
Hobbes
Posts: 2
Joined: 2011-09-21T04:06:44-07:00
Authentication code: 8675308

Re: compare -subimage-search very slow since 6.6.6-0

Post by Hobbes »

fmw42 wrote: Also your syntax is incorrect. The larger image must be first and null must have : after it as null:
Sorry, of course you are right. I changed the filenames in the posting to make them "self explaining", and mixed up the order. I tried with the colon after null, but it has no effect on the result:

compare -metric AE -subimage-search image.png part.png null:

Version: ImageMagick 6.6.5-3 2010-10-22 Q16
595 @ 362,310
Command took 0:0:2.31

Version: ImageMagick 6.6.6-0 2010-11-21 Q16
595 @ 362,310
Command took 0:1:5.83

Version: ImageMagick 6.7.2-7 2011-09-16 Q16
595 @ 362,310
Command took 0:1:13.14

My main point is that version 6.6.6-0 is more than 30 times slower than version 6.6.5-3.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compare -subimage-search very slow since 6.6.6-0

Post by fmw42 »

This is something the IM developers will have to check for you.

But you might identify your system and memory capacity.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: compare -subimage-search very slow since 6.6.6-0

Post by magick »

We'll investigate but it may be a few days before we get to this problem.
McGuive7
Posts: 1
Joined: 2015-08-06T20:43:16-07:00
Authentication code: 1151

Re: compare -subimage-search very slow since 6.6.6-0

Post by McGuive7 »

Any update on this one. I'm experiencing similarly long compare times, and I was hoping to set up an automated tool to compare larger screenshots of staging/live websites to check for differences. At these speeds, this task wouldn't be feasible (generating and comparing screenshots for numerous ages in a site) - do you have any advice and/or information on possible ways to optimize for this task (in addition to the original question, of increased delays). Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: compare -subimage-search very slow since 6.6.6-0

Post by snibgo »

Sub-image searches with IM are accurate but expensive because every pixel in the sub-image must be compared to every possible location in the large image. Speed can be massively improved by reducing the number of comparisons by resizing and/or cropping. See my page "Searching an image".
snibgo's IM pages: im.snibgo.com
Post Reply