%[mean] option - an aside

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

%[mean] option - an aside

Post by GreenKoopa »

While playing with a recent post I discovered that the following gives two different outputs:

Code: Select all

convert in.tif                         -channel G -set option:b "%[mean]" +delete label:%[b] out1.png
convert in.tif -set option:a "%[mean]" -channel G -set option:b "%[mean]" +delete label:%[b] out2.png
Once %[mean] is calculated, its value seems to stick for future instances on different images. The same held true for %[standard-deviation].
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: %[mean] option - an aside

Post by GreenKoopa »

A bug somewhere in here???

A +clone keeps the stuck value, while loading a second copy from the file fixes it.

Also notable, fx:mean appears to look at only the first channel.

Code: Select all

convert 01.tif -format "%[mean] %[fx:mean] %[standard-deviation] %[fx:standard_deviation]" info:
36120.1 0.564631 20950 0.318149

convert 01.tif -channel R -format "%[mean] %[fx:mean] %[standard-deviation] %[fx:standard_deviation]" info:
37003.1 0.564631 20849.9 0.318149

convert 01.tif -channel G -format "%[mean] %[fx:mean] %[standard-deviation] %[fx:standard_deviation]" info:
36685.3 0.564631 20928.2 0.318149

convert 01.tif -channel B -format "%[mean] %[fx:mean] %[standard-deviation] %[fx:standard_deviation]" info:
34672 0.564631 21071.3 0.318149
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: %[mean] option - an aside

Post by anthony »

The %[fx:mean] only returning red channel mean seems to me to be a bug.

The %[fx:....] was specifically designed to only do a single calculation on an image, returning the equivalent results of -fx with limitations of i=0, j=0 and for red channel output. This calculation pre-dated the addition of fx 'mean', and as such 'mean' caclulation may be adversely effected by the %[fx] environment.

However 'mean' is not channel specific. It probably should always return the same value as %[mean], unless a sub-channel request is made (if that is posible) %[fx:mean.r]

As such I would say only returning red channel is a bug. But the fact that it is unchanging is NOT a bug.

Are you sure %[fx:mean] value is just red channel? Could it actually be whole image mean?

ASIDE: I would also hope that in a normal -fx the value of 'mean' is cached on first lookup, and not re-calculated every time. Otherwise the slow fx would get very very much slower still.
Same goes for some of the
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: %[mean] option - an aside

Post by GreenKoopa »

anthony wrote: Are you sure %[fx:mean] value is just red channel? Could it actually be whole image mean?
I learned long ago to never be sure of anything. Maybe I can't convert between Q16, Q8, and % correctly, and I am certainly no ImageMagick wizard. In my second post I provided my 4 commands and 16 outputted numbers. If it helps, Photoshop gives me the following for RGB means: 143.98, 142.75, 134.91. It would be nice if someone else could look at those numbers and interpret what they see. If they concur that I am using the commands and interpreting the numbers correctly, I or they can try to reproduce this on a smaller image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: %[mean] option - an aside

Post by anthony »

Well 0.564631* 65535 => 37003.092585

whcih is the %[mean] report for just the red channel. So it does look as if the %[fx:mean] is only returning the mean of the red channel only.

It does clearly seem to be a bug!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: %[mean] option - an aside

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.6.5-8 Beta available by sometime tomorrow. Thanks,
Post Reply