Difference threshold value

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
sven
Posts: 27
Joined: 2003-10-02T02:21:38-07:00

Difference threshold value

Post by sven »

Hi magick,

I'd like to make a suggestion concerning the compare utility.
Currently, the comparison of two images works as follows:

If all color channels of pixel (x,y) of image A are equal to all color channels of pixel (x,y) of image B, this pixel is overlayed with 90 % white. If only one color channel differs, this pixel is overlayed with 90 % magenta.

I'd like to suggest to make this a little bit more flexible. An option like "-diff-threshold <value>" is 0 by default (current behaviour). If this value is set to 2, the following would be understood as an equal pixel as well:
  • Pixel (x,y) of image A is R80, G80, B80
  • Pixel (x,y) of image B is R81, G79, B80
difference in R --> 1
difference in G --> 1
difference in B --> 0
sum: 2

Background of this question:
We have experienced slight color differences when having either the PowerPC or the Intel Mac architecture while using Adobe InDesign CS3 resp. QuarkXPress 7 and working with transparencies. Such problems can be reproduced, meaning that you have a document with transparencies in InDesign and create a PDF document using a PowerPC and then using an IntelMac. When you then compare these PDF documents, you will recognize magenta-colored pixels. Moreover, this is not a problem of the RIP (e.g. Ghostscript, Photoshop). You can prove that this problem already exists in the PDF document.
In addition to that I a sure that such comparison threshold value would be nice, since these color differences can only be measured but not be seen.
By the way, this "problem" has already been confirmed by Adobe.

What do you think about this idea?
Thanks a lot in advance for your comments!

Kind regards,
Sven
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Difference threshold value

Post by anthony »

... overlayed with 90 % white ... 90 % magenta
Actually it is overlays with red not magenta. As as of some more recent version of IM the overlay tint percentage was change from 90% to 70%. I am not sure when that change however happened as I did not log it at the time (my bad).
I'd like to suggest to make this a little bit more flexible. An option like "-diff-threshold <value>" is 0 by default (current behaviour). If this value is set to 2, the following would be understood as an equal pixel as well:
Actually I also would like to see the output image -fuzz adjusted.
At the moment however -fuzz only adjusts the final output count for a -metric AE test the output image is unaffected.

See my notes at
http://imagemagick.org/Usage/compare/#compare
Some updates may appear in a day or two.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sven
Posts: 27
Joined: 2003-10-02T02:21:38-07:00

Re: Difference threshold value

Post by sven »

Hello anthony,

Thanks for your reply!
anthony wrote: Actually it is overlays with red not magenta. As as of some more recent version of IM the overlay tint percentage was change from 90% to 70%. I am not sure when that change however happened as I did not log it at the time (my bad).
Oh, I haven't noticed that change, but probably my version of IM is too old.
anthony wrote: Actually I also would like to see the output image -fuzz adjusted.
At the moment however -fuzz only adjusts the final output count for a -metric AE test the output image is unaffected.
An effect of the -fuzz option on the actual image would be a nice start. Do you know how fuzz works? Is the distance applied to each color channel (R, G and B) or somehow to the whole color? What would it mean to say -fuzz 2?

There might be a slight but important difference to what I described above. You won't be able to recognize a difference of 2 color values (manually) when considering the sum of differences over all color channels.

Example:
  • Pixel (x,y) of image A is R80, G80, B80
  • Pixel (x,y) of image B is R81, G79, B80
However, you will recongnize a difference if the color distance is meant for each color channel.

Example:
  • Pixel (x,y) of image A is R80, G80, B80
  • Pixel (x,y) of image B is R82, G78, B82
Thus, i think that the -fuzz option may not be enough and an option considering the distance as a sum would be great.
Any ideas?

Kind regards,
Sven
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Difference threshold value

Post by anthony »

sven wrote:Do you know how fuzz works? Is the distance applied to each color channel (R, G and B) or somehow to the whole color? What would it mean to say -fuzz 2?
The fuzz color test is based on a distance in 3 dimentional RGB color space (or whatever space the image is using) or 4 dimentional CYMK space. That is a Pythagorean distance is what is measured
See Im Example, expert notes (owl symboled), in Fuzz Factor - Matching Similar Colors for more detail.

Non percentage values are also dependent on the 'quality depth' of the IM you are using (typically 16 or 8bit).

Also note that the distances is also adjusted for transparency components such that two fully transparent colors will match, while semi-transparent colors are 'closer' than there full-opaque counterparts. You can see this effect in the curved areas shown in Color Quantization and Transparency

In anser to your specific question.
Example:
  • Pixel (x,y) of image A is R80, G80, B80
  • Pixel (x,y) of image B is R81, G79, B80
The distance is sqroot(1^2+1^2) or 1.414 Note -fuzz does take a floating point argument.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sven
Posts: 27
Joined: 2003-10-02T02:21:38-07:00

Re: Difference threshold value

Post by sven »

anthony wrote:Actually it is overlays with red not magenta. As as of some more recent version of IM the overlay tint percentage was change from 90% to 70%. I am not sure when that change however happened as I did not log it at the time (my bad).
Hi Anthony,

would it be possible to keep this value variable, since I cannot use it for any of my use cases? 70% is not enough white to clearly distinguish between small changes and the actual images. 90% was absolutely fine!

Kind regards,
Sven
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Difference threshold value

Post by anthony »

A better solution would be an option to generate a 'change mask'.

In fact that is directly posible...
http://imagemagick.org/Usage/compose/#changemask

Unlike "compare" the created mask can be controled by the "Fuzz Factor" and is basically a more complex form of a greyscaled, thresholded 'difference' image.
http://imagemagick.org/Usage/compose/#difference

Once you have the mask you can create your own colorized 'white'
image to compose with your colorized 'red' or change image.

In this way you can create the exact comparison image you want, for whatever purpose you want, with whatever control you want.

For examples of creating difference masks, see the background removal masking in
http://imagemagick.org/Usage/channels/#mask_bgnd
and the later example sections of that page.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sven
Posts: 27
Joined: 2003-10-02T02:21:38-07:00

Re: Difference threshold value

Post by sven »

Hi Anthony,

Thank you very much for your reply!
I will try your solution. However, I wonder whether this is considerably slower than the current solution...

Kind regards,
Sven
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Difference threshold value

Post by anthony »

It may be a little slower, but not by much, as compare is essentially doing exactly the same calls.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply