Problems with Image Statistics (fx:maxima etc.)

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.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Problems with Image Statistics (fx:maxima etc.)

Post by miket »

I'm running on IM 7.0.2-4 Q16 x86_64, using PerlMagick and getting some strange numbers from the fx:mean, fx:maxima, functions. These (I suspect) may be issues with the main IM program (rather than Perl Magick).

I'm also getting some strange numbers from the Perl Magick Statistics() method.

To illustrate (in Perl Magick - since I don't use the command line)

The (rather clumsy) code below generates a 3 pixel image including alpha channel and assigns different values to each pixel.

Code: Select all

    my $image = Image::Magick->new;
    my @pixel;
    $image->Set(size=>'3x1');
    $image->Read('canvas:black');

    $image->Color(color=>'blue');
    $image->Set(alpha=>'On');

    $image->SetPixel(x=>0, y=>0, color=>[1,1,0.75,1]);
    $image->SetPixel(x=>1, y=>0, color=>[1,0,0.5,0.2]);
    $image->SetPixel(x=>2, y=>0, color=>[0,0,0.25,1]);

    $image->Identify();

    print "Mean r = ".$image->Get('%[fx:mean.r]')."\n";
    print "Mean g = ".$image->Get('%[fx:mean.g]')."\n";
    print "Mean b = ".$image->Get('%[fx:mean.b]')."\n";
    print "Mean   = ".$image->Get('%[fx:mean]')."\n";
    print "Mean a = ".$image->Get('%[fx:mean.a]')."\n";
    print "Mean o = ".$image->Get('%[fx:mean.o]')."\n\n";

    print "Maxima r = ".$image->Get('%[fx:maxima.r]')."\n";
    print "Maxima g = ".$image->Get('%[fx:maxima.g]')."\n";
    print "Maxima b = ".$image->Get('%[fx:maxima.b]')."\n";
    print "Maxima   = ".$image->Get('%[fx:maxima]')."\n";
    print "Max      = ".$image->Get('%[fx:max]')."\n";
    print "Maxima a = ".$image->Get('%[fx:maxima.a]')."\n";
    print "Maxima o = ".$image->Get('%[fx:maxima.o]')."\n\n";

    print "Minima r = ".$image->Get('%[fx:minima.r]')."\n";
    print "Minima g = ".$image->Get('%[fx:minima.g]')."\n";
    print "Minima b = ".$image->Get('%[fx:minima.b]')."\n";
    print "Minima   = ".$image->Get('%[fx:minima]')."\n";
    print "Min      = ".$image->Get('%[fx:min]')."\n";
    print "Minima a = ".$image->Get('%[fx:minima.a]')."\n";
    print "Minima o = ".$image->Get('%[fx:minima.o]')."\n\n";


    my @stats = $image->Statistics();

    my ($i, $j);

    for ($i=0; $i<4; $i++) {
        for ($j=0; $j<8; $j++) {
            print $stats[$i*8+$j]."/";
        }
        print "\n";
    }
The Identify - verbose output is as follows

Code: Select all

Image: black
  Base filename: black
  Format: CANVAS (Constant image uniform color)
  Class: DirectClass
  Geometry: 3x1+0+0
  Units: Undefined
  Type: PaletteAlpha
  Base type: TrueColorAlpha
  Endianess: LSB
  Colorspace: sRGB
  Depth: 8/16-bit
  Channel depth:
    Red: 1-bit
    Green: 1-bit
    Blue: 16-bit
    Alpha: 4-bit
  Channel statistics:
    Pixels: 3
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 170 (0.666667)
      standard deviation: 120.208 (0.471405)
      kurtosis: -1.5
      skewness: -0.707107
      entropy: 0.918296
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 85 (0.333333)
      standard deviation: 120.208 (0.471405)
      kurtosis: -1.5
      skewness: 0.707107
      entropy: 0.918296
    Blue:
      min: 63.75 (0.25)
      max: 191.25 (0.75)
      mean: 127.5 (0.5)
      standard deviation: 52.0517 (0.204124)
      kurtosis: -1.5
      skewness: 0
      entropy: 1
    Alpha:
      min: 51 (0.2)
      max: 255 (1)
      mean: 187 (0.733333)
      standard deviation: 96.1665 (0.377124)
      kurtosis: -1.5
      skewness: -0.707107
      entropy: -nan
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 142.375 (0.558333)
      standard deviation: 101.066 (0.396337)
      kurtosis: -1.28206
      skewness: -0.213977
      entropy: 0.709148
  Colors: 3
  Histogram:
         1: (  0,  0, 64,255) #000040FF srgba(0,0,64,1)
         1: (255,  0,128, 51) #FF008033 srgba(255,0,128,0.2)
         1: (255,255,191,255) #FFFFBFFF srgba(255,255,191,1)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Tile geometry: 3x1+0+0
  Alpha color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 3x1+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2017-02-09T11:00:47+00:00
    date:modify: 2017-02-09T11:00:47+00:00
    signature: 2721d18926bbdf0ebf14e8943047e4232109e609a135f0b82fdd882059921cc9
  Tainted: True
  Filesize: 0B
  Number pixels: 3
  Pixels per second: 3PB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 7.0.2-4 Q16 x86_64 2016-12-05 http://www.imagemagick.org


This appears to give all the correct statistical data.

The output from the various fx:maxima, minima and mean functions are as follows:

Code: Select all

Mean r = 0.666667
Mean g = 0.333333
Mean b = 0.5
Mean   = 0.5
Mean a = 0
Mean o = 0

Maxima r = 1
Maxima g = 1
Maxima b = 0.749999
Maxima   = 0.749999
Max      = 0
Maxima a = 1
Maxima o = 1

Minima r = 0
Minima g = 0
Minima b = 0.250001
Minima   = 0.250001
Min      = 0
Minima a = 0.2
Minima o = 0.2

This is giving erroneous results for some of the returns.
  • fx:mean gives and incorrect value. It appears to actually give the value from fx:maxima.b
    fx:mean.a and fx:mean.o give incorrect values. Interestingly if the fx:mean call (just before the fx:mean.a call) is omitted the value of fx:mean.a changes (but is still incorrect) !
    fx:Maxima gives an incorrect value, again apearing to give the fx:maxima.b value.
    fx:Minima - as above.
    fx:Max & fx:Min give no values (and I didn't expect then to)
    All others appear to function as expected.
The output from the Perl Magick Statistics() method gives the following.

Code: Select all

1/0/1/0.333333333333333/0.471404520791032/-1.5/0.707106781186548/0.91829583405449/
16/0.25/0.75/0.5/0.204124145231932/-1.50000000000001/0/1/
4/0.2/1/0.733333333333333/0.377123616632825/-1.50000000000001/-0.707106781186548/-nan/
1/2.74310389084049e+303/-2.74310389084049e+303/0/0/0/0/-nan/

This appears to miss out the r channel, but gives correct values for the g,b,& a channels (albeit in the wrong place in the array)

Any chance you could take a look at these issues?

Regards

Mike
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problems with Image Statistics (fx:maxima etc.)

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick within a few days. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ within a few days.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Thanks guys (and gals). Great service & much appreciated :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Image Statistics (fx:maxima etc.)

Post by fmw42 »

You should upgrade your IM version. The maxima and minima issues seem gone for me.

But there are still errors in the alpha and overall statistics from the fx calculation for the mean and std. I think the overall statistics are just reflecting the issue with the alpha mean and std.

This was tested below using IM 7.0.4.7 with and without HDRI vs IM 6.7.4.7 all Q16. The IM 6 results are correct and consistent between the verbose values and the fx calculation. But there are issues with the IM 7 alpha mean and std from the fx calculations.

IM 7 below:


The code above colors are:

$image->SetPixel(x=>0, y=>0, color=>[1,1,0.75,1]);
$image->SetPixel(x=>1, y=>0, color=>[1,0,0.5,0.2]);
$image->SetPixel(x=>2, y=>0, color=>[0,0,0.25,1]);


So I created three images and appended them as follows:

Code: Select all

convert xc:"srgb(100%,100%,75%)" -alpha opaque test_0.png
convert xc:"srgb(100%,0%,50%)" -alpha set -channel alpha -evaluate set 20% +channel test_1.png
convert xc:"srgb(0%,0%,25%)" -alpha opaque test_2.png

Code: Select all

convert test_0.png test_1.png test_2.png +append test.png

From the above, I compute the following as proper statistics:

Red values are: 1,1,0 which should then have min=0, max=1, mean=0.6666, std=0.57735 (sample or unbiased) and 0.4714 (population).

Green values are: 1,0,0 which should then have min=0, max=1, mean=0.33333, std=0.57735 (sample or unbiased) and 0.4714 (population).

Blue values are: 0.75,0.5,0.25 which should then have min=0.25, max=0.75, mean=0.5, std=0.25 (sample or unbiased) and 0.20412 (population).

Alpha values are: 1,0.2,1 which should then have min=0.2, max=1, mean=0.73333, std=0.46188 (sample or unbiased) and 0.37712 (population).



If I do

Code: Select all

magick identify -verbose test.png

Code: Select all

  Channel statistics:
    Pixels: 3
    Red:
      min: 0 (0)
      max: 65535 (1)
      mean: 43690 (0.666667)
      standard deviation: 30893.5 (0.471405)
      kurtosis: -1.5
      skewness: -0.707107
      entropy: 0.918296
    Green:
      min: 0 (0)
      max: 65535 (1)
      mean: 21845 (0.333333)
      standard deviation: 30893.5 (0.471405)
      kurtosis: -1.5
      skewness: 0.707107
      entropy: 0.918296
    Blue:
      min: 16384 (0.250004)
      max: 49151 (0.749996)
      mean: 32767.7 (0.500003)
      standard deviation: 13377.1 (0.204121)
      kurtosis: -1.5
      skewness: -3.73774e-05
      entropy: 1
    Alpha:
      min: 13107 (0.2)
      max: 65535 (1)
      mean: 48059 (0.733333)
      standard deviation: 24714.8 (0.377124)
      kurtosis: -1.5
      skewness: -0.707107
      entropy: nan
  Image statistics:
    Overall:
      min: 0 (0)
      max: 65535 (1)
      mean: 36590.4 (0.558334)
      standard deviation: 25973.9 (0.396337)
      kurtosis: -1.28205
      skewness: -0.213982
      entropy: 0.709148

Code: Select all

magick test.png -format "min=%[fx:minima.r], max=%[fx:maxima.r], mean=%[fx:mean.r], std=%[fx:standard_deviation.r]\n" info:
min=0, max=1, mean=0.666667, std=0.471405

Code: Select all

magick test.png -format "min=%[fx:minima.g], max=%[fx:maxima.g], mean=%[fx:mean.g], std=%[fx:standard_deviation.g]\n" info:
min=0, max=1, mean=0.333333, std=0.471405

Code: Select all

magick test.png -format "min=%[fx:minima.b], max=%[fx:maxima.b], mean=%[fx:mean.b], std=%[fx:standard_deviation.b]\n" info:
min=0.250004, max=0.749996, mean=0.500003, std=0.204121

Code: Select all

magick test.png -format "min=%[fx:minima.a], max=%[fx:maxima.a], mean=%[fx:mean.a], std=%[fx:standard_deviation.a]\n" info:
min=0.2, max=1, mean=0, std=0 <--- mean and std bad

Code: Select all

magick test.png  -format "min=%[fx:minima], max=%[fx:maxima], mean=%[fx:mean], std=%[fx:standard_deviation]\n" info:
min=0, max=1, mean=0.375001, std=0.348608 <--- mean and std bad

If I use .o rather than .a, I still do not get the correct values:

Code: Select all

magick test.png -format "min=%[fx:minima.o], max=%[fx:maxima.o], mean=%[fx:mean.o], std=%[fx:standard_deviation.o]\n" info:
min=0, max=1, mean=0.375001, std=0.348608 <--- mean and std bad



Note that all std values reported by IM are the population std not the unbiased sample std. This was debated at viewtopic.php?f=2&t=30866&p=140251&hili ... le#p139992

The changelog at http://www.imagemagick.org/script/changelog.php says

Code: Select all

2016-11-18 7.0.3-8 Cristy <quetzlzacatenango@image...>
Off by 1 error when computing the standard deviation (reference https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=30866).
But it does not appear to be changed to the unbiased std, or was lost in some upgrade.


Reference to bugs and supposed fixes are at:

viewtopic.php?f=3&t=28650&p=127269&hili ... ma#p127269 (no final answer about mean error)

viewtopic.php?f=3&t=28565&p=126890&hili ... ma#p126890 (where minima and maxima was supposedly fixed)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Image Statistics (fx:maxima etc.)

Post by fmw42 »

This has been fixed in IM 7.0.4.8 along with a change to report the std as unbiased in IM 7 (rather than population).
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Thanks for the feedback Fred :). I'll update my IM and feedback wit any issues.

Mike
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Hmmmm..... Having updated to 7.4-8 I still appear to be having some issues (with some problems fixed). Before I respond, could you let me know if it is best to feedback on this thread, or to create a new thread?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problems with Image Statistics (fx:maxima etc.)

Post by magick »

This thread is fine. You need to download 7.0.4-9 beta from http://magick.imagemagick.org/download/beta/ before you post. We did fix one bug in the overall statistics generation.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Thanks. Missed the beta version, so will download/install tonight and respond tomorrow.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Hi Guys,

I've now installed v7.0.5-0.

On the plus side:
  • The Statistics() function in Perl Magik is now functioning correctly - Many thanks.
  • fx:maxima minima and mean now give the correct values - Many thanks.
However, when running the same PERL script as my initial posting on v7.0.5-0:
  • The fx:mean.r type channel calls (i.e. all .r .g .b .o .a for all mean maxima & minima fx commands) all simply give the mean of all channels rather than the individual channel. This appears to be contrary to the results from Fred's command line scripts in his earlier posts here (using v.7.0.4-7). Could this be an issue specific to PERL implementation?
Happy to provide more detail/scripts/outputs if necessary.

Mike
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Image Statistics (fx:maxima etc.)

Post by fmw42 »

I agree that there is now a bug in IM 7.0.5.0 with respect to the channel stats. I now get

Code: Select all

magick test.png -format "min=%[fx:minima.r], max=%[fx:maxima.r], mean=%[fx:mean.r], std=%[fx:standard_deviation.r]\n" info:
min=0, max=1, mean=0.558334, std=0.444579

Code: Select all

magick test.png -format "min=%[fx:minima.g], max=%[fx:maxima.g], mean=%[fx:mean.g], std=%[fx:standard_deviation.g]\n" info:
min=0, max=1, mean=0.558334, std=0.444579

Code: Select all

magick test.png -format "min=%[fx:minima.b], max=%[fx:maxima.b], mean=%[fx:mean.b], std=%[fx:standard_deviation.b]\n" info:
min=0, max=1, mean=0.558334, std=0.444579

Which are all wrong and as mentioned are giving the global stats and not the channel stats.

For example the stats from IM 6 for the blue channel give

Code: Select all

convert test.png -format "min=%[fx:minima.b], max=%[fx:maxima.b], mean=%[fx:mean.b], std=%[fx:standard_deviation.b]\n" info:
min=0.250004, max=0.749996, mean=0.500003, std=0.204121
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problems with Image Statistics (fx:maxima etc.)

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Thanks again wizards :)
miket
Posts: 60
Joined: 2016-08-12T13:19:13-07:00
Authentication code: 1151

Re: Problems with Image Statistics (fx:maxima etc.)

Post by miket »

Hi again.

I've now updated to v7.0.5.1.

Unfortunately it still appears to be giving incorrect values :(

The Statistics() function in perl (which was fixed in v7.0.5.0) now does not function. The values from the RG&B channels are now wrong. The alpha channel does, however, give the correct results.

The fx:mean individual channel functions all appear to work as expected, however the overall mean is now incorrect.

Unfortunately the fx:maxima / minima functions (which were fixed in v7.0.5.0) now no longer give sensible results.

Test code as follows:

Code: Select all

    my $image = Image::Magick->new;
    my @pixel;
    $image->Set(size=>'3x1');
    $image->Read('canvas:black');

    $image->Color(color=>'blue');
    $image->Set(colorspace=>"xyY");
    $image->Set(alpha=>'On');

    $image->SetPixel(x=>0, y=>0, color=>[0.2,0.1,0.7,0.1]);
    $image->SetPixel(x=>1, y=>0, color=>[0.2,0.2,0.5,0.2]);
    $image->SetPixel(x=>2, y=>0, color=>[0.9,0.8,0.2,0.4]);

    $image->Identify();

    print "Mean r = ".$image->Get('%[fx:mean.r]')."\n";
    print "Mean g = ".$image->Get('%[fx:mean.g]')."\n";
    print "Mean b = ".$image->Get('%[fx:mean.b]')."\n";
    print "Mean fx= ".$image->Get('%[fx:mean]')."\n";
    print "Mean   = ".$image->Get('%[mean]')."\n";
    print "Mean a = ".$image->Get('%[fx:mean.a]')."\n";
    print "Mean o = ".$image->Get('%[fx:mean.o]')."\n\n";

    print "Maxima r = ".$image->Get('%[fx:maxima.r]')."\n";
    print "Maxima g = ".$image->Get('%[fx:maxima.g]')."\n";
    print "Maxima b = ".$image->Get('%[fx:maxima.b]')."\n";
    print "Maxima   = ".$image->Get('%[fx:maxima]')."\n";
    print "Max      = ".$image->Get('%[max]')."\n";
    print "Maxima a = ".$image->Get('%[fx:maxima.a]')."\n";
    print "Maxima o = ".$image->Get('%[fx:maxima.o]')."\n\n";

    print "Minima r = ".$image->Get('%[fx:minima.r]')."\n";
    print "Minima g = ".$image->Get('%[fx:minima.g]')."\n";
    print "Minima b = ".$image->Get('%[fx:minima.b]')."\n";
    print "Minima   = ".$image->Get('%[fx:minima]')."\n";
    print "Min      = ".$image->Get('%[min]')."\n";
    print "Minima a = ".$image->Get('%[fx:minima.a]')."\n";
    print "Minima o = ".$image->Get('%[fx:minima.o]')."\n\n";


    my @stats = $image->Statistics();

    my ($i, $j);

    for ($i=0; $i<4; $i++) {
        for ($j=0; $j<8; $j++) {
            print $stats[$i*8+$j]."/";
        }
        print "\n";
     }
Output from Identify

Code: Select all

Image: black
  Base filename: black
  Format: CANVAS (Constant image uniform color)
  Class: DirectClass
  Geometry: 3x1+0+0
  Units: Undefined
  Type: PaletteAlpha
  Base type: TrueColorAlpha
  Endianess: LSB
  Colorspace: xyY
  Depth: 8/16-bit
  Channel depth:
    Channel 0: 16-bit
    Channel 1: 16-bit
    Channel 2: 16-bit
    Channel 3: 1-bit
    Alpha: 16-bit
  Channel statistics:
    Pixels: 3
    Channel 0:
      min: 51 (0.2)
      max: 229.5 (0.9)
      mean: 110.5 (0.433333)
      standard deviation: 103.057 (0.404145)
      kurtosis: -2.33333
      skewness: 0.3849
      entropy: 0.918296
    Channel 1:
      min: 25.5 (0.1)
      max: 204 (0.8)
      mean: 93.5 (0.366667)
      standard deviation: 96.5414 (0.378594)
      kurtosis: -2.33333
      skewness: 0.35491
      entropy: 1
    Channel 2:
      min: 51 (0.2)
      max: 178.5 (0.7)
      mean: 119 (0.466667)
      standard deviation: 64.1736 (0.251661)
      kurtosis: -2.33333
      skewness: -0.130129
      entropy: 1
    Channel 3:
      min: inf (2.7431e+303)
      max: -inf (-2.7431e+303)
      mean: 0 (0)
      standard deviation: -0 (-0)
      kurtosis: -3
      skewness: 0
      entropy: 0
    Alpha:
      min: 25.5 (0.1)
      max: 102 (0.4)
      mean: 59.5 (0.233333)
      standard deviation: 38.9519 (0.152753)
      kurtosis: -2.33333
      skewness: 0.207827
      entropy: 1
  Image statistics:
    Overall:
      min: 25.5 (0.1)
      max: 229.5 (0.9)
      mean: 95.625 (0.375)
      standard deviation: 72.2273 (0.283244)
      kurtosis: -1.23759
      skewness: 0.694478
      entropy: 0.979574
  Colors: 3
  Histogram:
         1: ( 51, 26,179, 26) #331AB31A xyya(51,26,179,0.1)
         1: ( 51, 51,128, 51) #33338033 xyya(51,51,128,0.2)
         1: (230,204, 51,102) #E6CC3366 xyya(230,204,51,0.4)
  Rendering intent: Undefined
  Gamma: 1
  Tile geometry: 3x1+0+0
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 3x1+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2017-03-05T12:47:16+00:00
    date:modify: 2017-03-05T12:47:16+00:00
    signature: cfe6e755dc12122eb7b2921d4d0ba61841c3a2079c3e8c32513d0ab594e3b614
  Tainted: True
  Filesize: 0B
  Number pixels: 3
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 7.0.5-1 Q16 x86_64 2017-03-05 http://www.imagemagick.org
Output from Test program

Code: Select all

Mean r = 0.433333
Mean g = 0.366667
Mean b = 0.466667
Mean fx=[color=#FF0000] 0.466667[/color]
Mean   = [color=#FF0000]30583[/color]
Mean a = 0.233333
Mean o = 0.233333

Maxima r = 0.9
Maxima g =[color=#FF0000] 0.9[/color]
Maxima b = [color=#FF0000]0.9[/color]
Maxima   = 0.9
Max      = 58981.5
Maxima a =[color=#FF0000] 0.9[/color]
Maxima o = [color=#FF0000]0.9[/color]

Minima r = [color=#FF0000]0.1[/color]
Minima g = 0.1
Minima b = [color=#FF0000]0.1[/color]
Minima   = 0.1
Min      = 6553.5
Minima a = 0.1
Minima o = 0.1

[color=#FF0000]1/2.7431038908404911996e+303/-2.7431038908404911996e+303/0/-0/-3/0/0/
1/2.7431038908404911996e+303/-2.7431038908404911996e+303/0/-0/-3/0/0/
1/2.7431038908404911996e+303/-2.7431038908404911996e+303/0/-0/-3/0/0/[/color]
16/0.10000000000000000555/0.4000000000000000222/0.23333333333333333703/0.15275252316519466467/-2.3333333333333348136/0.20782656212951647334/1/0.2
I've also noticed a spurious channel 3 which has appeared in the identify output (I'm using xyZ colorspace with Alpha channel). Is that normal?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Image Statistics (fx:maxima etc.)

Post by fmw42 »

There is an issue with the blue channel min and max values in 7.0.5-1 Q16 HDRI. Also the overall mean.

As before, I created three images and appended them as follows:

Code: Select all

convert xc:"srgb(100%,100%,75%)" -alpha opaque test_0.png
convert xc:"srgb(100%,0%,50%)" -alpha set -channel alpha -evaluate set 20% +channel test_1.png
convert xc:"srgb(0%,0%,25%)" -alpha opaque test_2.png
convert test_0.png test_1.png test_2.png +append test.png

Proper results for test.png are:

Red values are: 1,1,0 which should then have min=0, max=1, mean=0.6666, std=0.57735 (sample or unbiased) and 0.4714 (population).

Green values are: 1,0,0 which should then have min=0, max=1, mean=0.33333, std=0.57735 (sample or unbiased) and 0.4714 (population).

Blue values are: 0.75,0.5,0.25 which should then have min=0.25, max=0.75, mean=0.5, std=0.25 (sample or unbiased) and 0.20412 (population).

Alpha values are: 1,0.2,1 which should then have min=0.2, max=1, mean=0.73333, std=0.46188 (sample or unbiased) and 0.37712 (population).

I do not know how the overall values are computed in terms of how they are weighted by the alpha values.

Code: Select all

magick identify -verbose test.png

Code: Select all

    Red:
      min: 0 (0)
      max: 65535 (1)
      mean: 43690 (0.666667)
      standard deviation: 37836.6 (0.57735)
      kurtosis: -2.33333
      skewness: -0.3849
      entropy: 0.918296
    Green:
      min: 0 (0)
      max: 65535 (1)
      mean: 21845 (0.333333)
      standard deviation: 37836.6 (0.57735)
      kurtosis: -2.33333
      skewness: 0.3849
      entropy: 0.918296
    Blue:
      min: 16384 (0.250004)
      max: 49151 (0.749996)
      mean: 32767.7 (0.500003)
      standard deviation: 16383.5 (0.249996)
      kurtosis: -2.33333
      skewness: -2.03457e-05
      entropy: 1
    Alpha:
      min: 13107 (0.2)
      max: 65535 (1)
      mean: 48059 (0.733333)
      standard deviation: 30269.3 (0.46188)
      kurtosis: -2.33333
      skewness: -0.3849
      entropy: 0.918296
  Image statistics:
    Overall:
      min: 0 (0)
      max: 65535 (1)
      mean: 36590.4 (0.558334)
      standard deviation: 29135.5 (0.44458)
      kurtosis: -1.9149
      skewness: -0.151608
      entropy: 0.938722
The above seem correct, except for the overall mean, as described below


Using FX escapes:

Code: Select all

magick test.png -format "min=%[fx:minima.r], max=%[fx:maxima.r], mean=%[fx:mean.r], std=%[fx:standard_deviation.r]\n" info:
min=0, max=1, mean=0.666667, std=0.57735 <---- correct

Code: Select all

magick test.png -format "min=%[fx:minima.g], max=%[fx:maxima.g], mean=%[fx:mean.g], std=%[fx:standard_deviation.g]\n" info:
min=0, max=1, mean=0.333333, std=0.57735 <---- correct

Code: Select all

magick test.png -format "min=%[fx:minima.b], max=%[fx:maxima.b], mean=%[fx:mean.b], std=%[fx:standard_deviation.b]\n" info:
min=0, max=1, mean=0.500003, std=0.249996 <---- incorrect - should be min=0.25 and max=0.75

Code: Select all

magick test.png -format "min=%[fx:minima.a], max=%[fx:maxima.a], mean=%[fx:mean.a], std=%[fx:standard_deviation.a]\n" info:
min=0, max=1, mean=0.733333, std=0.46188 <---- correct

Code: Select all

magick test.png  -format "min=%[fx:minima], max=%[fx:maxima], mean=%[fx:mean], std=%[fx:standard_deviation]\n" info:
min=0, max=1, mean=0.558334, std=0.444579 <--- don't know how means are computed with alpha weights, but these agree with the verbose info:

If I take only the RGB values without alpha and average them, then I get a mean = (1+1+0.75+1+0+0.5+0+0+0.25)/9 = 4.5/9 = 0.5 = mean. So it puzzles me if alpha weighting is involved how that would make the average value larger at 0.558334.

If I weight the values by alpha, then I get a mean = (1+1+0.75+0.2+0+0.1+0+0+0.25)/9 = 3.3/9 = 0.3666667.

However, IM 6.9.7.10 Q16 (non-hdri) reports and overall mean and std as:

mean: 28944.7 (0.441667)
standard deviation: 29135.5 (0.44458)

which has a mean of 0.44167, which is less than 0.558334 as reported in IM 7 and less than my 0.5 mean for only the RGB channels.

So that clearly shows the overall mean from IM 7 is wrong.

The std values between IM 6 and IM 7 are consistent.
Post Reply