當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Imagick getImageChannelDistortions()用法及代碼示例


Imagick::getImageChannelDistortions()函數是PHP中的內置函數,用於將圖像的一個或多個圖像通道與重建圖像進行比較,並返回指定的失真度量。 getImageChannelDistortion()與getImageChannelDIstortions()之間的區別在於,後者不必接受通道參數,因此也隻能接受兩個參數。

用法:

float Imagick::getImageChannelDistortions( Imagick $reference,
             int $metric, int $channel = Imagick::CHANNEL_DEFAULT)

參數:此函數接受上述和以下所述的三個參數:


  • $reference:它指定圖像的Imagick對象。
  • $metric:它指定度量標準類型常量之一。
    METRIC常數列表如下:
    • 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:它指定對通道模式有效的通道常數。使用按位運算符組合十個以上的channeltype常量。通道常數的默認值為Imagick::CHANNEL_DEFAULT。

異常:該函數在錯誤時引發ImagickException。

返回值:此函數返回一個描述通道失真的雙精度圖。

以下示例程序旨在說明PHP中的Imagick::getImageChannelDistortions()函數:

程序1:

<?php 
  
// Create two new imagick object 
$imagick1 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
$imagick2 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190916133223/diamond.png'); 
  
// Get the distortion with METRIC constant as imagick::METRIC_MEANABSOLUTEERROR 
$distortion = $imagick1->getImageChannelDistortions($imagick2, 1); 
  
echo $distortion; 
?>

輸出:

23925

程序2:

<?php 
  
// Create two new imagick object 
$imagick1 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
$imagick2 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
// Get the distortion with METRIC constant as imagick::METRIC_MEANABSOLUTEERROR 
$distortion = $imagick1->getImageChannelDistortions($imagick2, 1); 
  
echo $distortion; 
?>

輸出:

0 because both of the images are same.

程序3:

<?php 
  
// Create two new imagick object 
$imagick1 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190823154611/geeksforgeeks24.png'); 
  
$imagick2 = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20190916133633/gausian.png'); 
  
// Get the distortion with METRIC constant as imagick::METRIC_MEANSQUAREERROR 
$distortion = $imagick1->getImageChannelDistortions($imagick2, 2); 
  
echo $distortion; 
?>

輸出:

0.048318723480804

參考: https://www.php.net/manual/en/imagick.getimagechanneldistortions.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | Imagick getImageChannelDistortions() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。