Friday, October 10, 2025
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

Most Popular

Dominic
32348 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6791 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS