#!/usr/bin/env python #-*- encoding: utf-8 -*- # # deriv_image.py # Compute the derivative of an image. # # Copyright (c) 2008 Pierre "delroth" Bourdon # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys try: from PIL import Image, ImageFilter, ImageChops, ImageOps, ImageEnhance except ImportError: print """To use this script, you must install the Python Imaging Library module, also known as PIL.""" sys.exit(1) mat = [ 0, -1, 0, -1, 2, 0, 0, 0, 0 ] def main(): if len(sys.argv) != 4: print "Usage: %s " % sys.argv[0] return 1 inp, out, passes = sys.argv[1:] im = Image.open(inp) for i in xrange(int(passes)): print "Pass", i im2 = im.filter(ImageFilter.Kernel((3, 3), mat, 1.0/3.0)) im3 = ImageChops.screen(im, im2) im = im3.filter(ImageFilter.SMOOTH) im3.save(out) return 0 if __name__ == "__main__": sys.exit(main())