PHP | Imagick compareImageChannels() Function

The Imagick::compareImageChannels() function is an inbuilt function in PHP which is used to return the difference between one or more than one images.

Syntax:

array Imagick::compareImageChannels( Imagick $image, int $channelType, int $metricType )

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

  • $image: This parameter holds the Imagick object which contains the image to compare.
  • $channelType: This parameter holds the Imagick channel constants which provides any channel constant that is valid for your channel mode. Use bitwise operator to combine one or more channel constants. Click here to get the list of channel constants.
  • $metricType: It is an Metric type constants. Click here to get the list of metric type constants.

Return Value: It returns an array of new_wand and distortion.

Errors/Exceptions: It throws ImagickException while error occured.



Below program illustrates the Imagick::compareImageChannels() function in PHP:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

      
<?php
  
// Store the image path into variables
$imagePath1 =
  
$imagePath2 =
  
$imagePath3 =
  
// Create new Imagick object
$imagick1 = new \Imagick($imagePath1);
$imagick2 = new \Imagick($imagePath2);
$imagick3 = new \Imagick($imagePath3);
  
// Use compareImageChannels() function to find
// the difference between images
$diff12 = $imagick1->compareImageChannels($imagick2,
        Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);
  
$diff13 = $imagick1->compareImageChannels($imagick3
        Imagick::CHANNEL_ALL, Imagick::METRIC_MEANABSOLUTEERROR);
  
// Print the difference in array
print_r($diff12);
print_r($diff13);
  
?>

chevron_right


Output:

Array ( [0] => Imagick Object ( ) [1] => 0.084920034052215 ) 
Array ( [0] => Imagick Object ( ) [1] => 0.63074787218949 ) 

Reference: https://www.php.net/manual/en/imagick.compareimagechannels.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.