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 than 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:
php
<?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 ; ?> |
Output:
23925
Program 2:
php
<?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 ; ?> |
Output:
0 because both of the images are same.
Program 3:
php
<?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 ; ?> |
Output:
0.048318723480804
Reference: https://www.php.net/manual/en/imagick.getimagechanneldistortions.php