# A fragment of a Python script that can act as a front end for # the assignment code. This code is intended to be used in a # command-line-driven implementation of the algorithm. import Image import PIL_usm # Load in the C++ support module import painthelp # The main painting algorithm described in the paper. 'src' is an # image loaded using PIL, and Rs is a Python list of brush radii. def paint( src, Rs ): # Construct a new image to serve as the canvas. For every # brush size, we'll pass in the current canvas and get back # a canvas with new strokes painted onto it. canvas = Image.new( 'RGB', src.size ) # Note that Hertzmann mentions a special colour that's maximally # far away from every other colour. You'll need to figure out # some way to make that work. for R in Rs: # Construct a Gaussian blurred version of the source image. ref = PIL_usm.gblur( src, f_sigma * R ) w,h = canvas.size # Turn the image data in canvas into a Python string. # As long as the image is in RGB format, you'll be able # to read this string in C++ as a sequence of RGB byte # triples. cts = canvas.tostring() # Call the paintLayer function in the C++ code and turn # the result into a new PIL image. canvas = Image.fromstring( 'RGB', (w,h), painthelp.paintLayer( cts, ref.tostring(), w, h, R ) ) return canvas