这是什么类型的phash算法


What type of phash Algorithm is this?

当我读到phash时,有四种类型:

  1. 基于离散余弦变换(DCT)
  2. 基于Marr-Hildreth算子
  3. 基于径向方差和
  4. 一种基于块均值的图像哈希函数

在下面的代码中,您可以看到,没有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";
?>

这个算法是什么类型的?

对我来说,它看起来像aHash,因为它根据图像的平均颜色计算哈希。