Open In App

PHP Imagick getImageChannelDistortions() Function

The Imagick::getImageChannelDistortions() function is an inbuilt function in PHP which is used to compare one or more image channels of an image to a reconstructed image and returns the specified distortion metrics. The difference between getImageChannelDistortion() and getImageChannelDIstortions() is that the latter doesn’t necessarily accepts a channel parameter thus it can take only two parameters also. 

Syntax:



float Imagick::getImageChannelDistortions( Imagick $reference,
             int $metric, int $channel = Imagick::CHANNEL_DEFAULT)

Parameters: This function accepts three parameters as mentioned above and described below:

Exceptions: This function throws ImagickException on error. 



Return Value: This function returns a double describing channel distortion. Below programs illustrate the Imagick::getImageChannelDistortions() function in PHP: 

Program 1: 




<?php
 
// Create two new imagick object
$imagick1 = new Imagick(
 
$imagick2 = new Imagick(
 
// Get the distortion with METRIC constant as imagick::METRIC_MEANABSOLUTEERROR
$distortion = $imagick1->getImageChannelDistortions($imagick2, 1);
 
echo $distortion;
?>

Output:

23925

Program 2: 




<?php
 
// Create two new imagick object
$imagick1 = new Imagick(
 
$imagick2 = new Imagick(
 
// Get the distortion with METRIC constant as imagick::METRIC_MEANABSOLUTEERROR
$distortion = $imagick1->getImageChannelDistortions($imagick2, 1);
 
echo $distortion;
?>

Output:

0 because both of the images are same.

Program 3: 




<?php
 
// Create two new imagick object
$imagick1 = new Imagick(
 
$imagick2 = new Imagick(
 
// Get the distortion with METRIC constant as imagick::METRIC_MEANSQUAREERROR
$distortion = $imagick1->getImageChannelDistortions($imagick2, 2);
 
echo $distortion;
?>

Output:

0.048318723480804

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


Article Tags :