Open In App

PHP | Imagick getImageChannelDistortion() Function

The Imagick::getImageChannelDistortion() function is an inbuilt function in PHP which is used to compare image channels of an image to a reconstructed image and returns the specified distortion metric.

Syntax:



float Imagick::getImageChannelDistortion( Imagick $reference,
                                  int $channel, int $metric )

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

Exceptions: This function throws ImagickException on error.



Return Value: This function returns TRUE on success.

Below programs illustrate the Imagick::getImageChannelDistortion() 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->getImageChannelDistortion($imagick2, 0, 1);
echo $distortion;
?>

Output:

122728

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->getImageChannelDistortion($imagick2, 0, 1);
echo $distortion;
?>

Output:

0

Note: In the second example output comes 0 because both of the image are same.

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


Article Tags :