PIL patches

From Noah.org
Jump to: navigation, search


?isn't this equivalent to:

    ImageStat.Stat(ImageChops.difference(i, im)).rms

-- Fredrik Lundh fredrik at pythonware.com

Add "difference_rms" method to the PIL

I originally wrote this to help implement a video stabilization filter. In video stabilization I take two frames of a video and shift one of them around until the RMS Difference is minimized. You could also use this to quantify how much a lossy compression algorithm distorts an image relative to some other compression algorithm.

This is a patch against the Python Imaging Library Imaging-1.1.6. This adds the method ImageChops.difference_rms(im1, im2) which returns a float of the RMS difference between the two given images, im1 and im2. This is about 10 times faster than doing it in Python. This can be used to detect changes in images (say, for motion detection) or to compare the effect of different image operations. If the two images are exactly equal then difference_rms() will return 0.0. As the images diverge the value returned will increase. It will always be a positive number. In general, the greater the difference between the two images then the greater the RMS difference will be.

To apply the patch and build PIL execute the following commands. This assumes that Imaging-1.1.6.tar.gz and Imaging-1.1.6.patch are in the same directory.

tar xzf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6
patch -p 1 < Imaging-1.1.6.patch
python setup.py install

Download patch

<include src="/var/www/usr/local/apache2/htdocs/engineering/src/python/Imaging-1.1.6.patch" highlight="diff" />