Page 1 of 1

Relationship between Imagick means and IM7 ?

Posted: 2018-07-13T11:49:11-07:00
by RoundedRectangle
I'm converting a script from Imagick in PHP to command line IM 7.
One thing has held me up for a while now.

This method in PHP:

Code: Select all

$im->getImageChannelMean(Imagick::CHANNEL_ALL);
Returns the following means for 5 arbitrary images I was testing with:

Code: Select all

22282.14894013
30473.356623976
38031.623559618
31193.137382776
13730.786592171
However using "magick identify -verbose" on those same 5 images, here are the means from the "Image statistics: Overall:" section:

Code: Select all

64.0298
118.573
147.983
90.7432
53.4272
What is the relation between these numbers, and how can I get the same number PHP returns (or close to it)?

Any help you can provide would be much appreciated.

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-13T12:36:20-07:00
by snibgo
The relationship between some pairs is a factor of 257.

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-13T15:10:32-07:00
by RoundedRectangle
snibgo wrote: 2018-07-13T12:36:20-07:00 The relationship between some pairs is a factor of 257.
It would make more sense if it were 255.

I'll take a larger sample then and either go with 257 if it's the most common, or average everything.

Thanks

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-13T16:21:20-07:00
by fmw42
That factor is due to your Imagick computing as -depth 8 and Imagemagick computing as -depth 16. Depth 8 has a range of 0 to 255. Depth 16 has a range of 0 to 65535. The factor is 65535/255=257.

If you want 8-bit depths from Q16 Imagemagick, then do

Code: Select all

magick image -format "%[fx:255*mean]\n" info:
or for each channel:

Code: Select all

magick image -format "%[fx:255*mean.r] %[fx:255*mean.g] %[fx:r255*mean.b]\n" info:
Note that fx reports values in the range of 0 to 1

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-14T02:12:03-07:00
by RoundedRectangle
getQuantumDepth() in PHP returns as Q16.

Also after testing about 100 images, there are only 20 around the 257 factor.

The factors themselves range from 127 to 3526, which leaves me scratching my head.

I'm going to sidestep the whole issue and just start fresh without Imagick.

Thanks

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-14T03:02:26-07:00
by snibgo
I suspect that your two methods are often measuring different things. Do your images have transparency? Perhaps one calculation includes the alpha channel but the other doesn't. Perhaps one uses transparency and the other uses opacity.

Incidentally, the overall mean of partially transparent images is reported differently for IM V6 and IM v7. Perhaps this accounts for your problem.

Code: Select all

f:\web\im>%IM%convert toes_holed.png -format %[fx:mean] info:
0.158904

f:\web\im>%IMG7%magick toes_holed.png -format %[fx:mean] info:
0.211775
For fully opaque images, they report the same values.

(Tested with v6.9.5-3 and v7.0-7-28 on Windows 8.1.)

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-14T03:45:08-07:00
by RoundedRectangle
Interesting.

Yes I've got a mix of grayscale, rgb, alpha and no aplha.

Honestly I need to do better normalization of my image set before processing them.

Re: Relationship between Imagick means and IM7 ?

Posted: 2018-07-14T03:58:03-07:00
by snibgo
In general terms, the "mean" of an image that contains transparency is ambiguous. We might actually want the mean of the colour channels only (eg RGB or gray, but not including alpha), but we might want to ignore the colour of pixels that are fully transparent (so a transparent pixel that happens to be black, white or anything else doesn't affect the mean), and so on.

It all depends on what you want the value to signify.