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."
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.
Code: Select all
use Image::Magick; my $quantumDepth = Image::Magick->QuantumDepth; print "QuantumDepth = $quantumDepth\n";
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
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;
my $quantumDepth = 0.+Image::Magick->QuantumDepth;
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]')
($alphaMax,$redMax,$blueMax) = $image->Statistics('max[arb]')
Cheers all, and belated greetings to Anthony, Fred, and The Wizard.
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
(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'