Ok, I found a reasonable solution using the ImageStat module to get the sum of pixels of the difference image. This gives the manhattan distance when divided by the pixel count and averaged over RGB.<div><br></div><div><div>
In [151]: def idiff(im1,im2):</div><div> return array(ImageStat.Stat(ImageChops.difference(im1,im2)).sum).mean()/(im1.size[0] * im1.size[1])</div><div> .....: </div><div><br></div><div>In [153]: timeit("idiff(anna,f37)",20)</div>
<div>Out[153]: 0.023978149890899657</div><div><br></div><div>Let me know if there is any faster solution short of coding in some distance functions to the C modules (which I did consider, before be reminded of my pitiful ignorance...)</div>
<div><br></div><div>Yours, </div><div><br></div><div>-nsh</div><br><div class="gmail_quote">On Sat, Dec 5, 2009 at 7:56 PM, Lauri Love (nsh) <span dir="ltr"><<a href="mailto:lauri.love@gmail.com">lauri.love@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">i'm coding a project which requires quick comparison of two images per pixel by colorspace (distance is the sum of the squares of the differences of RGB values over the pixels of the images), as a fitness function (i am trying to recreate/extend roger alsing's genetic mona lisa code in python).<div>
<br></div><div>creating an absolute difference image takes about 1/100th of a second on my (eeepc) hardware, but i can't figure out a way to reduce the difference image to an integer of float value quickly. it takes about the order of 5 seconds to iterate through all the pixels and sum the RGB values to get the manhattan distance. "manually" calculating the manhattan or euclidean distances between the two images is even slower. </div>
<div><br></div><div>can anyone suggest a way to quickly get either distance from two images?</div><div><br></div><div>sincerely and gratefully, </div><div><br></div><font color="#888888"><div>-nsh</div>
</font></blockquote></div><br></div>