Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
dams
Posts: 2 Joined: 2013-10-27T01:18:19-07:00
Authentication code: 6789
Post
by dams » 2013-10-27T01:21:32-07:00
Hello
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 it reaches a given threshold.
Code: Select all
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 ?
Code: Select all
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 ?
Code: Select all
bool Imagick::modulateImage ( float $brightness , float $saturation , float $hue )
dams
Posts: 2 Joined: 2013-10-27T01:18:19-07:00
Authentication code: 6789
Post
by dams » 2013-10-27T06:56:11-07:00
Here is my code:
Code: Select all
function doIt($file) {
$im = new Imagick( $file );
// resize by 200 width and keep the ratio
$stats = $im->getImageChannelStatistics();
// Print Statistics
// ---------------------------------------------
$maxima = $stats[imagick::CHANNEL_RED]['maxima'];
$lum_i = ( $stats[imagick::CHANNEL_RED]['mean'] + $stats[imagick::CHANNEL_RED]['mean'] + $stats[imagick::CHANNEL_RED]['mean'] ) / (3 * $maxima);
print_r(' =>' . $file . ' : ');
print_r($lum_i);
$lum_max = 0.4;
if ($lum_i > $lum_max) {
$factor =$lum_max / $lum_i;
print_r(" /!\ correction: ");
print_r($factor * 100);
//$im->negateimage(false);
$im->modulateimage($factor * 100);
//$im->negateimage(false);
}
$im->writeImage();
}
The correction factor seems to work, but modulateimage does nothing, even if I manually set $factor to 0.
What is the correct usage of modulateimage ?
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2013-10-27T12:55:04-07:00
Sorry, I only use command-line. I would think modulateimage() is like the "-modulate" command, but it might not be.