Open In App

PHP | Imagick getImageChannelMean() Function

The Imagick::getImageChannelMean() function is an inbuilt function in PHP which is used to get the mean and standard deviation of one or more image channels. It returns an associative array containing the keys as “mean” and value as “standardDeviation”. Syntax:

array Imagick::getImageChannelMean(int $channel)

Parameters: This function accepts a single parameter $channel which holds the channel constant that is valid for your channel mode. Use bitwise operator to combine more than one channeltype constants. Exceptions: This function throws ImagickException on error. Return Value: This function returns TRUE on success. Below programs illustrate the Imagick::getImageChannelMean() function in PHP: Program 1: 






<?php
 
// Create new imagick object
$imagick = new Imagick(
 
// Get the mean with CHANNEL constant as 1
// which corresponds to imagick::CHANNEL_RED
$mean = $imagick->getImageChannelMean(1);
 
print_r($mean);
?>

Output:

Array( [mean] => 56510.812968516 [standardDeviation] => 20404.259764873 )

Program 2: 






<?php
 
// Create new imagick object
$imagick = new Imagick(
 
// Get the mean with CHANNEL constant as 5
// which corresponds to imagick::CHANNEL_MAGENTA
$mean = $imagick->getImageChannelMean(5);
 
print_r($mean);
?>

Output:

Array ( [mean] => 57217.085522456 [standardDeviation] => 18896.296535248 )

Reference: https://www.php.net/manual/en/imagick.getimagechannelmean.php

Article Tags :