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:

  • $reference: It specifies the Imagick object of image.
  • $metric: It specifies one of the metric type constants.
    List of METRIC constants are given below:

    • imagick::METRIC_UNDEFINED (0)
    • imagick::METRIC_MEANABSOLUTEERROR (1)
    • imagick::METRIC_MEANSQUAREERROR (2)
    • imagick::METRIC_PEAKABSOLUTEERROR (3)
    • imagick::METRIC_PEAKSIGNALTONOISERATIO (4)
    • imagick::METRIC_ROOTMEANSQUAREDERROR (5)
  • $channel: It specifies the channel constant that is valid for channel mode. Use bitwise operator to combine more ten one channeltype constants. The default value of channel constants is Imagick::CHANNEL_DEFAULT.

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

23925

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

0 because both of the images are same.

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

0.048318723480804

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




My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.