2

As i read about phash, there are four types:

  1. A discrete Cosine transform (DCT) based
  2. A Marr-Hildreth operator based
  3. A radial variance based and
  4. A block mean value based image hash function.

in the below code you can see that, there is no DCT section. just simply generating the mean code and hash value. i am sure that, it may be Block mean value based hash function. but in that block-mean value, the algo doesn't has any secret keys.

    <?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";
?>

what is the type of this algo?

deceze
  • 510,633
  • 85
  • 743
  • 889
  • 1
    I agree with your sentiment that this is a block mean-value based image hash. What makes you think that a secret key is required? – Martin Mar 11 '12 at 17:42
  • As Block Mean Based Hashing has four methods (http://phash.org/docs/pubs/thesis_zauner.pdf) i had this doubt. Even though, i couldn't figure out the correct BMB method. – user1153410 Mar 13 '12 at 04:27

1 Answers1

0

For me it looks like aHash, as it calculates hash based on average colour of image.

Mantas
  • 4,259
  • 2
  • 27
  • 32