Open In App

PHP | Imagick getImageChannelDistortion() Function

Last Updated : 19 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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:
  • reference: It specifies the Imagick object to compare with.
  • channel: It specifies the channel constant that is valid for your channel mode. To apply more than one channel, combine channeltype constants using bitwise operators.
  • metric: It specifies one of the metric type constants. List of METRIC constants are given below:
    • imagick::METRIC_UNDEFINED (integer)
    • imagick::METRIC_MEANABSOLUTEERROR (integer)
    • imagick::METRIC_MEANSQUAREERROR (integer)
    • imagick::METRIC_PEAKABSOLUTEERROR (integer)
    • imagick::METRIC_PEAKSIGNALTONOISERATIO (integer)
    • imagick::METRIC_ROOTMEANSQUAREDERROR (integer)
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
<?php

// Create two new imagick object
$imagick1 = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png');
$imagick2 = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/20191112223241/trans9.png');

// Get the distortion with METRIC constant as imagick::METRIC_MEANABSOLUTEERROR
$distortion = $imagick1->getImageChannelDistortion($imagick2, 0, 1);
echo $distortion;
?>
Output:
122728
Program 2: php
<?php

// Create two new imagick object
$imagick1 = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png');
$imagick2 = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png');

// 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

Similar Reads