What's the proper way to grab different chunks of the statistics array returned by $image->Statistics()? At the moment I only need the means of the RGB in the normalized range [0,1], and I kludged it like so:
my @stats = $image->Statistics();
my $maxQ = -1+ (1<<$image->Get('depth'));
my ($rMean, $gMean, $bMean) = @stats[3,8,13];
printf("\n(* means: %g, %g, %g *)\n", $rMean/$maxQ, $gMean/$maxQ, $bMean/$maxQ);
It's the bold-faced line that is the worst form, obviously. What should I use? It's clear which array elements to use, as the the doc says,
"The returned values are an array of depth, minima, maxima, mean, and standard deviation values in RGB, CMYK, RGBA, or CMYKA order (depending on the image type)."
As for the normalization, I'll take suggestions there, too. I gather that Statistics() returns different depths for different channels, but the values of the data in the channels seem to be given relative to the maximum depth of the channels, which I presume is the return of $image->Depth(). Or is it relative to the QuantumDepth?
That's a lot of gathering, seeming and presuming, and I don't feel too secure with it.
By the way, the method for getting the QuantumDepth ought to be in the PerlMagick doc; I found it on this forum (magick's post): "Image::Magick->QuantumDepth returns the PerlMagick quantum depth."
Rick
Statistics()
Re: Statistics()
We documented the PerlMagick constants (available tomorrow).
You found a bug in Statistics() and we have a patch for the next point release of ImageMagick. The values returned should be normalized so they return consistent results no matter what the depth of the image or the QuantumDepth of the ImageMagick release.
You found a bug in Statistics() and we have a patch for the next point release of ImageMagick. The values returned should be normalized so they return consistent results no matter what the depth of the image or the QuantumDepth of the ImageMagick release.
Re: Statistics()
What to make of this? The code I quoted,
[/size]
gives
Argument "Image::Magick" isn't numeric in subroutine entry at F:/Perl/site/lib/Image/Magick.pm line 43.
but does also give
QuantumDepth = 16
Rick
Code: Select all
use Image::Magick;
my $quantumDepth = Image::Magick->QuantumDepth;
print "QuantumDepth = $quantumDepth\n";
gives
Argument "Image::Magick" isn't numeric in subroutine entry at F:/Perl/site/lib/Image/Magick.pm line 43.
but does also give
QuantumDepth = 16
Rick
Re: Statistics()
We cannot reproduce the problem. We're using Perl 5.10.0. Try adding 0 to Image::Magick->QuantumDepth so it switches to a numeric context.
Re: Statistics()
I shoulda mentioned it. I'm so:magick wrote:We cannot reproduce the problem. We're using Perl 5.10.0.
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
Version: ImageMagick 6.4.5 2008-10-24 Q16 http://www.imagemagick.org
Same results with thisTry adding 0 to Image::Magick->QuantumDepth so it switches to a numeric context.
my $quantumDepth = 0+Image::Magick->QuantumDepth;
and this
my $quantumDepth = 0.+Image::Magick->QuantumDepth;
Re: Statistics()
It slipped my mind at the time (one short decade ago) to follow up on this, as we got a bit sidetracked (as we will again). In returning to the original perl script that got this started, I found that my implementation no longer worked, because the array elements have moved or expanded. Had I followed up properly at the time this might have been averted. Namely, I meant to suggest that the elements should be named, rather than (or rather, in addition to) being deposited as just an array. The docs presently say this:
Since the previous post, the elements kurtosis, skewness, and entropy have been added, which accounts for the present failure of my script.Statistics() returns the image statistics for each channel in the image. The returned values are an array of depth, minima, maxima, mean, standard deviation, kurtosis, skewness, and entropy values in RGB, CMYK, RGBA, or CMYKA order (depending on the image type).
@statistics = $image->Statistics();
The current (and former) usage is a pain to resolve if you just want the means or whatever, not to mention the obvious possibility of more broken code down the road.
How hard would it be to allow for the bits to be picked off with identifiers that could have some longevity? For instance, perhaps, along the lines of such:
$redMean = $image->Statistics('mean-red')
@rgbMeans = $image->Statistics('mean[rgb]')
or even
($alphaMax,$redMax,$blueMax) = $image->Statistics('max[arb]')
Cheers all, and belated greetings to Anthony, Fred, and The Wizard.
Re: Statistics()
And for the side(tracked) issue ...
returns the correct value, but gives a (strict) warning. On my system (Centos 6.9; ImageMagick 7.0.7-15 Q16 x86_64 2018-01-17; Perl v5.10.1) I get
I wonder if the problem was not reproduced due to the non-strict invocation.
At the the end of the Perlmagick installation instructions is this:
Apologies if this belongs in the Bugs forum.
Rick
The problem was with this, 10 years ago, but it is the same today:magick wrote:We cannot reproduce the problem. We're using Perl 5.10.0.
Code: Select all
Image::Magick->QuantumDepth
(The module was named Magick.pm at the time.)Argument "Image::Magick" isn't numeric in subroutine entry at /usr/local/lib64/perl5/Image/Magick/Q16HDRI.pm line 56.
I wonder if the problem was not reproduced due to the non-strict invocation.
At the the end of the Perlmagick installation instructions is this:
If I do that, no error message appears, probably because it isn't strictly invoked. I get the warning this way:Finally, verify the PerlMagick install worked properly, type
perl -MImage::Magick -le 'print Image::Magick->QuantumDepth'
Code: Select all
perl -w -MImage::Magick -le 'print Image::Magick->QuantumDepth'
Rick
Re: Statistics()
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 @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.