2012-03-07 22 views
2

正如我讀到phash,有四種類型:什麼類型的phash算法是這樣的?

  1. 離散餘弦變換基於(DCT)
  2. 甲馬爾-希爾德里斯操作者基於
  3. 徑向基於方差的和
  4. A嵌段平均基於值的圖像散列函數。

在下面的代碼中可以看到,沒有DCT部分。只是簡單地生成平均代碼和散列值。我相信,它可能是基於塊均值的散列函數。但是在這個塊的平均值中,算法沒有任何祕密密鑰。

<?php 

    $filename = 'image.jpg'; 

    list($width, $height) = getimagesize($filename); 


    $img = imagecreatefromjpeg($filename); 

    $new_img = imagecreatetruecolor(8, 8); 


    imagecopyresampled($new_img, $img, 0, 0, 0, 0, 8, 8, $width, $height); 

    imagefilter($new_img, IMG_FILTER_GRAYSCALE); 


    $colors = array(); 
    $sum = 0; 


    for ($i = 0; $i < 8; $i++) { 

     for ($j = 0; $j < 8; $j++) { 

      $color = imagecolorat($new_img, $i, $j) & 0xff; 

      $sum += $color; 
      $colors[] = $color; 

     } 
    } 

    $avg = $sum/64; 


    $hash = ''; 
    $curr = ''; 

    $count = 0; 
    foreach ($colors as $color) { 

     if ($color > $avg) { 

      $curr .= '1'; 
     } else { 

      $curr .= '0'; 
     } 

     $count++; 

     if (!($count % 4)) { 

      $hash .= dechex(bindec($curr)); 

      $curr = ''; 
     } 

    } 

    print $hash . "\n"; 
?> 

這個算法是什麼類型的?

+1

我同意你的觀點,這是一個基於塊的基於平均值的圖像哈希。是什麼讓你認爲需要密鑰? – Martin 2012-03-11 17:42:29

+0

由於基於塊基於平均值的哈希有四種方法(http://phash.org/docs/pubs/thesis_zauner.pdf),我有這個疑問。儘管如此,我無法弄清楚正確的BMB方法。 – user1153410 2012-03-13 04:27:30

回答

0

對我來說,它看起來像aHash,因爲它會根據圖像的平均顏色計算散列值。