possible bug compare IM 6.7.3.1 Q16

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug compare IM 6.7.3.1 Q16

Post by fmw42 »

IM 6.7.3.1 Q16 Mac OSX Tiger

One of my scripts, nearestcolor, is failing now. I think I have traced the issue down to compare not working properly. It seems to always return the first pixel in a very simple compare operation. I am testing one color to see if compare can find it in a 3 color image with one pixel for each color.

convert -size 1x1 xc:white xc:red xc:black +append tmp.gif
compare -metric rmse -dissimilarity-threshold 100% -subimage-search \
tmp.gif \( -size 1x1 xc:red \) null:
30893.5 (0.471405) @ 0,0

result should be a perfect match to pixel 0,1


Similarly if I switch the first and last (white and black pixels), it still returns the first pixel

convert -size 1x1 xc:black xc:red xc:white +append tmp.gif
compare -metric rmse -dissimilarity-threshold 100% -subimage-search \
tmp.gif \( -size 1x1 xc:red \) null:
21845 (0.333333) @ 0,0


This also fails:
convert -size 1x1 xc:black xc:red xc:white +append brw.png
convert -size 1x1 xc:red red1.png
compare -metric rmse -dissimilarity-threshold 100% -subimage-search brw.png red1.png null:
21845 (0.333333) @ 0,0

As does this:

compare -metric rmse -dissimilarity-threshold 1 -subimage-search brw.png red1.png null:
21845 (0.333333) @ 0,0


My suspicion has to do with a 1D search. Note this works fine:

convert rose: rose.png
convert rose: -gravity center -crop 20x20+0+0 +repage rose_c20.png
compare -metric rmse -dissimilarity-threshold 100% -subimage-search rose.png rose_c20.png null:
0 (0) @ 25,13



A second issue is a complete failure, if I try to create the 3x1 3 color image in a parenthesis (yet the one parenthesis works fine as above)

compare -metric rmse -dissimilarity-threshold 100% -subimage-search \
\( -size 1x1 xc:white xc:red xc:black -append \) \( -size 1x1 xc:red \) null:
compare: unrecognized option `-append' @ error/compare.c/CompareImageCommand/371.
Last edited by fmw42 on 2011-10-16T17:14:46-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug compare IM 6.7.3.1 Q16

Post by fmw42 »

Any information or confirmation of this issue, yet?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug compare IM 6.7.3.1 Q16

Post by fmw42 »

This also fails. I had thought perhaps it was a 1D issue, but this shows it is not.


convert -size 10x10 xc:black xc:red xc:white +append brw10.png
convert -size 10x10 xc:red red10.png
compare -metric rmse -dissimilarity-threshold 100% -subimage-search brw10.png red10.png null:
21845 (0.333333) @ 0,0

The correct result should be at 11,0.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug compare IM 6.7.3.1 Q16

Post by magick »

ImageMagick uses the normalized correlation coefficient for template matching. NCC fails for images of constant color. We'll need to check for constant color and revert to distance squared. Look for a patch in ImageMagick 6.7.3-2 Beta within a few days.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug compare IM 6.7.3.1 Q16

Post by fmw42 »

This used to work in my nearestcolor script when I first created it in 4/2/2009 (about IM 6.5.1.x). So I take it you made change to use NCC at some point from rms dist. So does that mean it is ignoring -metric rmse or just reporting the metric even though the match is done by ncc?

Why don't you make the compare use the -metric for the type of matching. I thought that was what it was for. So if one wants to use ncc

compare -metric ncc -subimage-match image1 image2 result

or if one wants to use rms distance

compare -metric rmse -subimage-match image1 image2 result

Is that practical?


I don't understand how you will know from the images whether it is constant color, unless you only look at the small image to see if it is constant color. I guess that is what you mean.


Any way, thank for looking into this and fixing it.

P.S

You must have changed it at about:

2010-11-23 6.6.6-0 Cristy <quetzlzacatenango@image...>
Support NCC (normalized cross correlation) compare metric.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug compare IM 6.7.3.1 Q16

Post by magick »

We considered -metric as a solution to this problem and it seems you concur. Give us a few days and we'll get a patch in ImageMagick 6.7.3-2 Beta. Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug compare IM 6.7.3.1 Q16

Post by anthony »

I also always thought that "compare" always did vector color difference comparisons for images, and sub-image searches. If it is not what I have been telling people on the forums has been wrong.

I would also prefer to have it still do default searches using the defined metric (and its default).
As such a "ncc" metric would be an acceptable solution.

Though if "ncc" is only for sub-image searching then a warning should be produced when it isn't a sub-image search. The reference manual also needs to be updated.

As part of IMv7 I will be looking at methods to merge the special uses of "compare", "montage", etc as operations in "magick" (yet to be created) This however is still a long way off, as I am still working though existing options, modifying them so I can apply them in the strict 'as I see them' order. Also making lots of notes about where/how various settings set stored/used, and making adjustments. Eventually this should make for a much more exactly reference manual.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply