wolves Posted September 23, 2006 Share Posted September 23, 2006 someone knows how to compare one image to another one?likehow many percent dog.gif is equal to dog1.gif ?tks Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/ Share on other sites More sharing options...
shocker-z Posted September 23, 2006 Share Posted September 23, 2006 huh?? ???you mean like size of image or what?RegardsLiam Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97242 Share on other sites More sharing options...
FrOzeN Posted September 23, 2006 Share Posted September 23, 2006 I *think* he means go through them pixel by pixel and adding one to a counter for every (x, y) pixel that corresponds to the other image. Then produce a percentage of pixels that match to the total of pixels in the image.I haven't worked with images in php yet, so I'm not sure the code you would use, but the above would be the concept. Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97250 Share on other sites More sharing options...
wolves Posted September 23, 2006 Author Share Posted September 23, 2006 [quote author=FrOzeN link=topic=109181.msg439944#msg439944 date=1159022622]I *think* he means go through them pixel by pixel and adding one to a counter for every (x, y) pixel that corresponds to the other image. Then produce a percentage of pixels that match to the total of pixels in the image.[/quote]yes, I think that this is the idea.someone knows a script for it? tks Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97339 Share on other sites More sharing options...
Orio Posted September 23, 2006 Share Posted September 23, 2006 [code]<?phpif(imagesx($pic1)==imagesx($pic2) && imagesy($pic1)==imagesy($pic2)){ echo("Equal");}?>[/code]Something like this??Orio. Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97343 Share on other sites More sharing options...
wolves Posted September 23, 2006 Author Share Posted September 23, 2006 image 1 has 4 squares and 2 circlesimage 2 has 3 circles and 4 triangle image 3 has 3 oval formas and 3 squaresso image 1 seems more to image 3 of image 2 Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97405 Share on other sites More sharing options...
AndyB Posted September 23, 2006 Share Posted September 23, 2006 [quote author=wolves link=topic=109181.msg440106#msg440106 date=1159048916]so image 1 seems more to image 3 of image 2 [/quote]To a human, yes. Comparing one image to another pixel by pixel assigns no relevance to the shapes made by all the pixels or their relative spatial arrangement. For example: I have an image with four large squares in a row, and another image that's a copy of the first but half the width and half the size. To a human those have some degree of 'match'. On a pixel-by-pixel basis those probably don't match at all. Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97407 Share on other sites More sharing options...
wolves Posted September 23, 2006 Author Share Posted September 23, 2006 [code]those probably don't match at all.[/code]ok but, the image seem more with for large squares of another image with 6 small circles ? Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97410 Share on other sites More sharing options...
AndyB Posted September 23, 2006 Share Posted September 23, 2006 [quote author=wolves link=topic=109181.msg440111#msg440111 date=1159049540][code]those probably don't match at all.[/code]ok but, the image seem more with for large squares of another image with 6 small circles ?[/quote]'Seem' is the human intuitive analysis result. A php script in entirely logical, i.e. non-intuitive. Here's another example. Image 1 is a coin; image 2 is the same image rotated 1 degree. Human says they're the same, computer says they're different. I don't know what you're trying/hoping to do, but it isn't going to happen with a logical language. Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97414 Share on other sites More sharing options...
wolves Posted September 23, 2006 Author Share Posted September 23, 2006 "Seem" sorry but english is not my native language so it is bad :(ok I will put my problem..I need to analyze images of pieces of wood, small pieces but good resolutionIm my database there are lots of diferent imagesNow, I have a new image, so I have to compare to the others to see if I have this one or not.Why not a script that look the all the images and return me some images that looks like to my imagenot a perfect comparaison, but a aproximate Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97416 Share on other sites More sharing options...
Barand Posted September 23, 2006 Share Posted September 23, 2006 This will do a pixel-by-pixel comparison of 2 same-size gif images and produce a mask of those pixels where the color is different. It also reports the % different.[code]<?php$filea = $_GET['f1'];$fileb = $_GET['f2'];$im1 = imagecreatefromgif($filea);$im2 = imagecreatefromgif($fileb);$w1 = imagesx($im1);$w2 = imagesx($im2);$h1 = imagesx($im1);$h2 = imagesx($im2);$w = min($w1, $w2);$h = min($h1, $h2); $im3 = imagecreate($w,$h+25);$bg3 = imagecolorallocate($im3,0xff,0xff,0xff);$fg3 = imagecolorallocate($im3,0xff,0x00,0xff);$fg3t = imagecolorallocate($im3,0x00,0x00,0x00);$total_pixels = $w*$h;$diff = 0;for ($x=0; $x<$w; $x++) { for ($y=0; $y<$h; $y++) { if (imagecolorat($im1, $x, $y) != imagecolorat($im2, $x, $y)) { $diff++; imagesetpixel($im3, $x, $y, $fg3); } }}imagerectangle($im3,0,0,$w-1, $h-1, $fg3t);$pcdiff = number_format(floor($diff/$total_pixels * 100), 0) . '%';imagestring($im3, 3, 4, $h+3, $pcdiff, $fg3t);imagedestroy($im1);imagedestroy($im2);header("content-type: image/png");imagepng($im3);imagedestroy($im3);?>[/code]Call with <img src='compareImage.php?f1=a.gif&f2=b.gif'>where a.gif and b.gif are the images to be compared. Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97427 Share on other sites More sharing options...
wolves Posted September 23, 2006 Author Share Posted September 23, 2006 it is creating a new image with all diferences between img 1 and img 2but always 0% of diference,I will try to fixtks Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97433 Share on other sites More sharing options...
Barand Posted September 23, 2006 Share Posted September 23, 2006 If it's very small % changes, change$pcdiff = number_format(floor($diff/$total_pixels * 100), 0) . '%';to$pcdiff = number_format($diff/$total_pixels * 100, 2) . '%'; Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97437 Share on other sites More sharing options...
wolves Posted September 24, 2006 Author Share Posted September 24, 2006 it is working but see this imageshttp://www.set.eesc.usp.br/lamem/Texturas/Angelim.JPGhttp://www.set.eesc.usp.br/lamem/Texturas/Cedrilho.JPGthey are total diferent analizing it by pixels, but not really total diferentthe number of pixel is the number of different pixelsso if u compare this other imagehttp://www.set.eesc.usp.br/lamem/Texturas/PauBrasil.JPGwill be 100% diferent too . . .complex images will always return 100% of diference :-\ Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97446 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 try this version which converts to high contrast grayscale. Small adjustments to contrast have large effect on result.[code]<?php$filea = $_GET['f1'];$fileb = $_GET['f2'];$im1 = imagecreatefromjpeg($filea);$im2 = imagecreatefromjpeg($fileb);$w1 = imagesx($im1);$w2 = imagesx($im2);$h1 = imagesx($im1);$h2 = imagesx($im2);$w = min($w1, $w2);$h = min($h1, $h2); $im3 = imagecreate($w,$h+25);$bg3 = imagecolorallocate($im3,0xff,0xff,0xff);$fg3 = imagecolorallocate($im3,0xff,0x00,0xff);$fg3t = imagecolorallocate($im3,0x00,0x00,0x00);$total_pixels = $w*$h;$diff = 0;imagefilter($im1, IMG_FILTER_GRAYSCALE); imagefilter($im2, IMG_FILTER_GRAYSCALE);imagefilter($im1,IMG_FILTER_CONTRAST, 88); imagefilter($im2,IMG_FILTER_CONTRAST, 88); for ($x=0; $x<$w; $x++) { for ($y=0; $y<$h; $y++) { if (imagecolorat($im1, $x, $y) != imagecolorat($im2, $x, $y)) { $diff++; imagesetpixel($im3, $x, $y, $fg3); } }}imagerectangle($im3,0,0,$w-1, $h-1, $fg3t);$pcdiff = number_format(floor($diff/$total_pixels * 100), 0) . '%';imagestring($im3, 3, 4, $h+3, $pcdiff, $fg3t);imagedestroy($im1);imagedestroy($im2);header("content-type: image/png");imagepng($im3);imagedestroy($im3);?>[/code] Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97450 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 [quote=php manual imagecolorat()]$rgb = ImageColorAt($im, 100, 100);$r = ($rgb >> 16) & 0xFF;$g = ($rgb >> 8 ) & 0xFF;$b = $rgb & 0xFF;[/quote]applies to truecolor images, GD2 Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-97461 Share on other sites More sharing options...
wolves Posted September 25, 2006 Author Share Posted September 25, 2006 tks all especially Barand =) Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-98065 Share on other sites More sharing options...
wolves Posted December 8, 2006 Author Share Posted December 8, 2006 now I need to compare ".pgm" filesthere is a away to do this in php?i looked at docs, but I found nothing about .pgm Link to comment https://forums.phpfreaks.com/topic/21773-image-comparison/#findComment-137401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.