Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | Imagick getImageDistortion() Function

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:




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


Output:

0.97254902124405

Program 2:




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


Output:

0.020707619325613

Program 3:




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


Output:

0 because both images are same.

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

RELATED ARTICLES

Most Popular

Recent Comments