Open In App

PHP | Imagick getImageChannelDistortion() Function

Last Updated : 19 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
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
  
// 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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads