Page 1 of 2

Compare -FUZZ <- how it is calculated

Posted: 2017-11-10T05:51:13-07:00
by nastar
Hi everyone,
I need to know what does some values mean.
For example:

1) magick compare -metric AE -fuzz 0% -extract 350x200+459+175 Org.png Compare.png OrgDiff00.png
2) magick compare -metric AE -fuzz 0.5% -extract 350x200+459+175 Org.png Compare.png OrgDiff05.png
3) magick compare -metric AE -fuzz 1% -extract 350x200+459+175 Org.png Compare.png OrgDiff10.png

In 1st case as output i've got "67138", in 2nd case i've got "250" and in 3rd i've got "3".
So i've got this many pixels different but how this FUZZ exactly works?
What does it mean this 0.5% or 1%?
I've tried to check it and on org.png there are pixels with value 11,11,11, next on the right is 143,143,143 and 3rd 227,227,227 on compare.png pixels value are 14,14,14, next 145,145,145 and the last is 227,227,227.
With fuzz 0% 1st and 2nd pixels are diff, with fuzz 0.5% only 1st is diff, with fuzz 1.8% all three are good.

What i would like to know is what value in RGB is equal to 1% for example.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-10T12:44:21-07:00
by snibgo
Pixels have three dimensions of colour: R, G and B. We could plot them on a graph, but it would need 3 dimensions, a cube. The cube has a diagonal length, eg from black at one vertex to white at the opposite vertex.

Each pixel defines a point in this 3D space. Fuzz defines a sphere centred on that point. The radius of the sphere is a percentage of the cube diagonal.

So you have three examples. 67138 pixels in one image not exactly equal to corresponding pixels in the other image. 250 pixels are outside spheres, centred on corresponding pixels, of radius 0.5%. And only 3 are outside spheres radius 1%.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-12T16:51:14-07:00
by anthony
Actually without a percentage Fuzz defines that sphere in terms of pixel value distance.

But while Fuzz is a sphere for opaque RGB values it is a lot more complex when transparency is involved. The sphere remains the same but the distance between the pixels gets closer as the pixles become more transparent.

Example of how Fuzz works is shown on
http://www.imagemagick.org/Usage/color_ ... z_distance

From that guide...
Setting the "-fuzz" factor as a percentage, makes its use a lot simpler. In this case '100%' represents a large enough fuzz factor to cover all colors. That is, it represents the color distance from 'black' to 'white', across the 3 dimensional diagonal of the RGB color cube.
For an exact answer to the original subject question...
I have listed the various possible fuzz factor formulas that could, and were, implemented at some point during IM development, as well as the final formula used, see the bottom of the page http://www.imagemagick.org/Usage/bugs/f ... /#formulas

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T07:09:24-07:00
by nastar
Hi again,
Thank You both for explaining all things but... Unfortunately it mismatch with my excel file witch i did based on Formula used in IM.

I made 1x1 image.
For px 0,0,0,255 and 255,255,255,255 i've got 6 502,5 with Fuzz 1% and 6 502 500 with Fuzz 100%.
Based on above from black to white range is 6 502 500. Shouldn't be 16 581 375?
For above example in IM result with -metric PAE is 65 535 (1). Which i believe 1 = 100% for Fuzz.

EDIT:
To be more specific.
I'm using IM to compare two *png files that contains graphic and text.
One image was taken on one machine, second on other. I don't know specification first machine.
I would like to make almost perfect copy of first image.
Problem is with text mostly. On the first machine there is different aliasing for it than on the second one.
I manage to check that IM is so smart that if i move a letter 1px left/right, he will show it as error. That's great for me.
Now i need to know everything about color range to calculate threshold value and to explain what those values mean.

Thank You for all suggestions.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T07:47:45-07:00
by snibgo
nastar wrote:I made 1x1 image.
For px 0,0,0,255 and 255,255,255,255 i've got 6 502,5 with Fuzz 1% and 6 502 500 with Fuzz 100%.
Based on above from black to white range is 6 502 500. Shouldn't be 16 581 375?
For above example in IM result with -metric PAE is 65 535 (1). Which i believe 1 = 100% for Fuzz.
I don't understand this. Please show the commands you used, and the results.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T08:18:04-07:00
by nastar
For my Excel file i used:
fx:(100)*sqrt( ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 )*u.a*v.a/3 + (u.a-v.a)^2 )

For IM i used: magick compare -metric PAE -fuzz 0% 1px1st.png 1px2nd.png 1pxdiff.png

This is 1x1px image.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T08:38:58-07:00
by snibgo
Please show how you create 1px1st.png and 1px2nd.png, and your complete commands.

Otherwise, I have to guess, and I will guess wrong.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T09:28:01-07:00
by nastar
I used GIMP to creat 1x1 image.
Then i fill one image with 0,0,0 (RGB). Second image i fill with 255,255,255.
To compare i used:

magick compare -metric PAE -fuzz 0% 1px1st.png 1px2nd.png 1pxdiff.png
65535 (1)

As output i get 65535 (1). So with 100% fuzz or with fuzz 65535 i should get both pixels equal.

Then i used:

magick compare -metric AE -fuzz 65535 1px1st.png 1px2nd.png 1pxdiff.png
0

As output i got 0 while i put -fuzz 65535 or -fuzz 100%.

When i put same values in excel i've got:
with -fuzz 0% = 0
with -fuzz 1% = 65025
with -fuzz 100% = 6502500

For excel i use this formula as in previous post.

I even used the 'buggy' formula and i get same results.

I just want to put for example -fuzz 3% and then i know that this is equal for example 5 in R, 5 in B and 5 in G range.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T10:04:59-07:00
by snibgo
nastar wrote:As output i get 65535 (1). So with 100% fuzz or with fuzz 65535 i should get both pixels equal.

Then i used:

magick compare -metric AE -fuzz 65535 1px1st.png 1px2nd.png 1pxdiff.png
0

As output i got 0 while i put -fuzz 65535 or -fuzz 100%.
Yes. As you say, with 100% you get both pixels equal. IM reports the number that are different is 0. No pixels are different. So that is as you expect.

I don't know what formula gives you 6502500.
nastar wrote:I just want to put for example -fuzz 3% and then i know that this is equal for example 5 in R, 5 in B and 5 in G range.
It isn't. "-fuzz" is a sphere, not a cube. In Q16, a 3% fuzz has a radius of 0.03*65535 = 1966.05 .

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T10:20:36-07:00
by nastar
snibgo wrote: 2017-11-13T10:04:59-07:00 I don't know what formula gives you 6502500.
I used this formula:
"%[fx:(100)*sqrt( ( (u.r-v.r)^2 +
(u.g-v.g)^2 +
(u.b-v.b)^2 )*u.a*v.a/3 + (u.a-v.a)^2 ) ]%%"
I thought that 100 = fuzz 100%. I think here i might have error.
snibgo wrote: 2017-11-13T10:04:59-07:00
nastar wrote:I just want to put for example -fuzz 3% and then i know that this is equal for example 5 in R, 5 in B and 5 in G range.
It isn't. "-fuzz" is a sphere, not a cube. In Q16, a 3% fuzz has a radius of 0.03*65535 = 1966.05 .
I'm using 8bit per channel. So your example is for my image?
Then probably last question.
1966.05 is radius or diameter?

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T10:39:44-07:00
by snibgo
nastar wrote:I'm using 8bit per channel.
But you seem to be using IM Q16, because the output from compare PAE is 65535. This is 16 bits, not 8 bits.

1966.05 is the radius (on a scale of 0 to 65535), not diameter.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T10:55:53-07:00
by nastar
Using Windows, in properties in Bit Depth there is 24bit (8bit per channel).
In Photoshop/Gimp there is also 8bit per channel when i'm using color sample tool.

What about function?

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T11:27:21-07:00
by snibgo
The file is 8 bits/channel. But after IM has read the image, that is whatever Q-number your IM is. If you use Q8, the image has 8 bits/channel. Q16 makes the image 16 bits/channel. Q32 makes it 32 bits/channel.

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T11:47:10-07:00
by nastar
So by default IM write output as Q16?

And if i use:
magick compare -metric PAE -fuzz 0% 1px1st.png 1px2nd.png -depth 16 1pxDiff.png
This should output Q8 number not Q16?

Re: Compare -FUZZ <- how it is calculated

Posted: 2017-11-13T12:56:30-07:00
by snibgo
nastar wrote:So by default IM write output as Q16?
It's not that simple.

You can set the output depth with -depth or +depth, but:

JPEG is always 8 bits/channel. GIF is up to 256 colours, each of which is 8 bits/channel. PNG is either 8 or 16. TIFF is anything.

Within those limits, the output depth is often set to the input depth. For PNG files, IM may reduce the bit depth if that doesn't change the image.