PHP | Imagick getImageDistortion() Function

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

Syntax:

float Imagick::getImageDistortion(Imagick $reference, int $metric)

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

  • $reference: It specifies the Imagick object which need to compare.
  • $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)

Exceptions: This function throws ImagickException on error.



Return Value: This function returns the distortion metric used on the image.

Below programs illustrate the Imagick::getImageDistortion() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick1 = new Imagick(
  
$imagick2 = new Imagick(
  
// Get the distortion with METRIC constant
// as imagick::METRIC_ROOTMEANSQUAREDERROR
$distortion = $imagick1->getImageDistortion($imagick2, 5);
  
echo $distortion;
?>

chevron_right


Output:

0.97254902124405

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick1 = new Imagick(
  
$imagick2 = new Imagick(
  
// Get the distortion with METRIC constant
// as imagick::METRIC_PEAKSIGNALTONOISERATIO
$distortion = $imagick1->getImageDistortion($imagick2, 4);
  
echo $distortion;
?>

chevron_right


Output:

0.020707619325613

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick1 = new Imagick(
  
$imagick2 = new Imagick(
  
// Get the distortion with METRIC constant
// as imagick::METRIC_ROOTMEANSQUAREDERROR
$distortion = $imagick1->getImageDistortion($imagick2, 4);
  
echo $distortion;
?>

chevron_right


Output:

0 because both images are same.

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.