Py Portrait Artist



Introduction                                 Description                                Download          



Introduction:


This simple program lets you convert a photograph into an artsy looking portrait. This works best if the photograph is a closeup of face. My goal is to couple this with Lego robotics to make a robot that draws portraits. I plan to generate the NXC program that draws the image using python which can then be compiled and uploaded to the Lego NXT platform. I have not completed the robot part yet.


Description

This is my first attempt to dabble in image processing. This script is written in python and requires the Python Imaging Library (PIL) to run.

It has all the elements of the canny edge detector, but it is slightly different and the sequence of steps and the exact steps are different. First the Sobel kernel is used for edge detection (Sobel Edge Detection) and then the output is smoothed using a couple of rounds of median smoothing (Where each pixel is reset to its median value of the neighbors). Finally global thresholding is applied (Pixels with color above a threshold is discarded) and the resulting image is saved. There is also an option to enlarge the image and there are couple of "brushes" which can be used for different effects. Just the median smoothing on the edges gives it a splotchy effect as if it was drawn using blots or a thick brush. The brushes can give additional effects. Some of the portraits have been called "artistically interesting" (not sure what it exactly means though)

Options:
These are the options currently supported. You might need to tewak them for your picture. I am planning to add in the future, automatic tweaking of the options based on the input image.

maskThresh : This is the threshold for pixels to be retained after smoothing. This is a percentage of the total number of pixels before smoothing. A histogram is generated and the color that captures the percentage of pixels is taken as threshold.

maskSize : The mask size for median smoothing.

numIter: The number of smoothing rounds.

xmag, ymag: These parameters can be used for magnifying the image and also skewing it (magnifying in the ratio that is different from the original picture). Magnification is recomended when using the brushes.

brushes: When the image is magnified, there are lot of holes and the bushes can be used to blow up a pixel into a circle or a line or another pattern. When the image is scaled down again, it looks like it had been painted by a specific brush. For example using lines that are oriented randomly gives it an appearance of charcoal painting.


Download:

Source:  pyDraw.py

Note: You need Python Imaging Library (PIL) to run.


Examples:
Here are some of the portraits generated by this program. These images were generated and then scaled down using paint to be more viewable using browser.

Example1:

 

Example 1

Example2:

 

Example 2









 

SourceForge.net Logo