/ Published in: PHP
КлаÑÑ Ð´Ð»Ñ ÑÑ€Ð°Ð²Ð½ÐµÐ½Ð¸Ñ Ð´Ð²ÑƒÑ… изображений. Возвращает раÑÑтоÑние Ð¥Ñмминга. Подробнее можно почитать здеÑÑŒ: http://habrahabr.ru/blogs/image_processing/120562/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Hamming { private function _resizeImage($from_file, $to_file, $width, $height, $quality) { } private function _grayScaleImage($filename) { $width = $img_size[0]; $height = $img_size[1]; for ($c = 0; $c < 256; $c++) { } } private function _getPixelValue($filename, $x, $y) { $r = ($color >> 16) & 0xFF; $g = ($color >> 8) & 0xFF; $b = $color & 0xFF; } private function _getChainOfBits($image) { $this->_resizeImage($image, $tmpfile, 8, 8, 100); $this->_grayScaleImage($tmpfile); for($i=0; $i<8; $i++) { for($j=0; $j<8; $j++) { $rgb = $this->_getPixelValue($tmpfile, $i, $j); $a[] = $rgb['r']; } } $s = ''; foreach ($a as $value) { $s .= ($value > $avrg ? '0' : '1'); } return $s; } public function getDistance($image1, $image2) { $bits1 = $this->_getChainOfBits($image1); $bits2 = $this->_getChainOfBits($image2); $distance = 0; for($i=0; $i<64; $i++) { $bit1 = $bits1[$i]; $bit2 = $bits2[$i]; if ( $bit1 != $bit2 ) { $distance++; } } return $distance; } } $hamming = new Hamming(); $distance = $hamming->getDistance('image-1.jpg', 'image-2.jpg'); echo $distance;
URL: http://habrahabr.ru/blogs/image_processing/120562/