问题
I'm trying to compute the average brightness of an image using Imagemagick's getImageChannelStatistics function. I will then use modulateImage to decrease the brightness if if reaches a given threshold.
array Imagick::getImageChannelStatistics ( void )
1st question: The returned mean value of each channel is greater than 255, although the color depth is 8. How to interpret these values ?
Array ( [mean] => 27510.293108724 [minima] => 0 [maxima] => 65535 [standardDeviation] => 23761.909802897 [depth] => 8 )
Array ( [mean] => 22654.046931424 [minima] => 0 [maxima] => 65535 [standardDeviation] => 21085.309916751 [depth] => 8 )
Array ( [mean] => 21137.418988715 [minima] => 0 [maxima] => 65535 [standardDeviation] => 20369.810455127 [depth] => 8 )
2nd question: What is the relation between the mean value and brightness of an image ?
bool Imagick::modulateImage ( float $brightness , float $saturation , float $hue )
Thanks in advance!
回答1:
1st question: The mean value is the arithmetic mean (average) of all pixels in a channel. It is relative to the quantum depth which is either 8 or 16 bits depending on a compile-time setting. You can call getQuantumRange to get the minimum and maximum quantum value. The range should be either 0 - 255 or 0 - 65535. If you divide the mean value by the quantum range maximum, you get a value normalized to the range 0.0 - 1.0.
2nd question: modulateImage converts the image to the colorspace specified by the operational control modulate:colorspace which is HSL (hue/saturation/lightness) by default and can be changed with setOption. Then the lightness value of every pixel is multiplied by the brightness parameter, the saturation value is multiplied by the saturation parameter, and the hue parameter is added to the hue value. A brightness parameter b will approximately result in an image with a mean pixel value multiplied by b. It depends on the exact colorspace conversion and potential clipping of pixel values. More details can be found on the ImageMagick Color Modifications example page.
If you want to change only brightness and contrast, levelImage or contrastStretchImage are probably more efficient.
来源:https://stackoverflow.com/questions/19615938/php-imagemagick-statistics-usage