These pages are written by only Japanese.
|
Namazu for hns による簡易全文検索です。 詳細は 詳細指定/ヘルプをご参照下さい。 |
|||||||||||||||||||||||||||||||||||||||||||||||||||
<?php /* * dissimilarity measure * sum of squared difference * 2011/10/13- yoya@awm.jp */ function usage() { echo "Usage: php bitmap_comp.php <file1> <file2>\n"; } if (($argc != 3) || (! is_readable($argv[1])) || (! is_readable($argv[2]))) { usage(); exit (1); } $data1 = file_get_contents($argv[1]); $data2 = file_get_contents($argv[2]); $im1 = imagecreatefromstring($data1); $im2 = imagecreatefromstring($data2); if ($im1 === false || $im2 === false) { echo "Error: image1 or image2 has broken."; exit (1); } $width1 = imagesx($im1); $height1 = imagesy($im1); $width2 = imagesx($im2); $height2 = imagesy($im2); $width_ratio = $width2 / $width1; $height_ratio = $height2 / $height1; if ($width_ratio < 0.5 || 2.0 < $width_ratio || $height_ratio < 0.5 || 2.0 < $height_ratio) { echo "Error: image1(".$width1."x".$height1.") image2(".$width2."x".$height2.")\n"; exit (1); } $width = min($width1, $width2); $height = min($height1, $height2); $distance_square_sum = 0; for ($y = 0 ; $y < $height ; $y++) { for ($x = 0 ; $x < $width ; $x++) { $i1 = imagecolorat($im1, $x, $y); $i2 = imagecolorat($im2, $x, $y); $rgb1 = imagecolorsforindex($im1, $i1); $rgb2 = imagecolorsforindex($im2, $i2); $red_diff = $rgb1['red'] - $rgb2['red']; $green_diff = $rgb1['green'] - $rgb2['green']; $blue_diff = $rgb1['blue'] - $rgb2['blue']; $distance_square_sum += $red_diff*$red_diff + $green_diff*$green_diff + $blue_diff*$blue_diff; } } echo $distance_square_sum / ($width * $height) . "\n";