Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 这是什么类型的phash算法?_Php_Image_Hash_Phash - Fatal编程技术网

Php 这是什么类型的phash算法?

Php 这是什么类型的phash算法?,php,image,hash,phash,Php,Image,Hash,Phash,当我读到phash时,有四种类型: 一种基于离散余弦变换(DCT)的小波变换 基于Marr-Hildreth算子 基于径向方差的遗传算法 基于块平均值的图像哈希函数 在下面的代码中,您可以看到,没有DCT部分。只需简单地生成平均代码和散列值。我确信,它可能是基于块平均值的哈希函数。但是在块平均值中,算法没有任何密钥 <?php $filename = 'image.jpg'; list($width, $height) = getimagesize($filen

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

  • 一种基于离散余弦变换(DCT)的小波变换
  • 基于Marr-Hildreth算子
  • 基于径向方差的遗传算法
  • 基于块平均值的图像哈希函数
  • 在下面的代码中,您可以看到,没有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

    对于我来说,它看起来像是基于图像平均颜色计算哈希值的
    aHash

    我同意你的观点,这是一个基于块平均值的图像哈希值。是什么让你认为需要一个密钥呢?因为基于块均值的散列有四种方法(),我对此表示怀疑。尽管如此,我还是想不出正确的BMB方法。我同意你的观点,这是一个基于块平均值的图像哈希。是什么让你认为需要一个密钥呢?因为基于块均值的散列有四种方法(),我对此表示怀疑。尽管如此,我还是想不出正确的BMB方法。