HomeLanguagesPHP | Imagick getImageChannelDistortion() Function

PHP | Imagick getImageChannelDistortion() Function

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS