首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这是什么类型的phash算法?

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

Stack Overflow用户
提问于 2012-03-07 07:03:56
回答 1查看 1.9K关注 0票数 2

当我读到关于phash的文章时,有四种类型:

基于离散余弦变换(

  1. )的
  2. 基于Marr-Hildreth算子的
  3. 径向方差和基于
  4. A块均值的图像散列函数

在下面的代码中,您可以看到,没有DCT部分。只是简单地生成平均代码和哈希值。我确信,它可能是基于块均值的散列函数。但在那个块平均值中,algo没有任何秘密密钥。

代码语言:javascript
复制
    <?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";
?>

这种阿尔戈是什么类型的?

EN

回答 1

Stack Overflow用户

发布于 2015-11-10 13:40:58

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9597121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档