2
正如我读到phash,有四种类型:什么类型的phash算法是这样的?
- 离散余弦变换基于(DCT)
- 甲马尔-希尔德里斯操作者基于
- 径向基于方差的和
- 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";
?>
这个算法是什么类型的?
我同意你的观点,这是一个基于块的基于平均值的图像哈希。是什么让你认为需要密钥? – Martin 2012-03-11 17:42:29
由于基于块基于平均值的哈希有四种方法(http://phash.org/docs/pubs/thesis_zauner.pdf),我有这个疑问。尽管如此,我无法弄清楚正确的BMB方法。 – user1153410 2012-03-13 04:27:30