Programming Digital Media
Filters

Filters

In the pixel tutorial we treated the digital image as a mosaic of colored tiles. For this tutorial, we'll process images using filters that operate on the image as a whole. Or at least, that's what it looks like; the underlying software still "gets" and "puts" pixel values as we did in the pixel tutorial. The filters operate at a higher level of abstraction — we can think of the pixels as a lower level way of conceptualizing the digital image (lateral metaphors notwithstanding).

The filter scripts in this tutorial are all Python wrappers for Apple software in the Core Image system. I have used SWIG to wrap the Core Image code so that we can use these filters in our Python programs.

Installing the software and images

To install the module, you need to copy two files to the image directory we created. (These are new versions that include the filter code, so you need to copy them again if you've already installed them.)

    Image.py
    _image.so

For all of the Python scripts below, you can click on the image to download the script. The filter name is a link to the Apple documentation of the Core Image filter wrapped by the Python code.

All the scripts below use one or more of the images below as input, so you will need to download them, too.







duchamp.tif
puchamd.tif
pdm.tif
Click on the filter names to read about what the arguments mean. Then change the argument values and rerun the script. Download some images from the Web and try modifying them.

ColorControls



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorControls(1, .3, .5) 
 
p.save("ColorControls.jpg") 

ExposureAdjust



from Image import * 
 
p = Image("duchamp.tif") 
p.ExposureAdjust(-1) 
 
p.save("ExposureAdjust.jpg") 

GammaAdjust



from Image import * 
 
p = Image("duchamp.tif") 
p.GammaAdjust(2.2) 
 
p.save("GammaAdjust.jpg") 

HueAdjust



from Image import * 
 
p = Image("duchamp.tif") 
p.HueAdjust(2) 
 
p.save("HueAdjust.jpg") 

ColorInvert



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorInvert() 
 
p.save("ColorInvert.jpg") 

ColorPosterize



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorPosterize(5) 
 
p.save("ColorPosterize.jpg") 

SepiaTone



from Image import * 
 
p = Image("duchamp.tif") 
p.SepiaTone(.8) 
 
p.save("SepiaTone.jpg") 

BumpDistortion



from Image import * 
 
p = Image("duchamp.tif") 
p.BumpDistortion(Vector(p.width/2,p.height/2), 120, 5) 
 
p.save("BumpDistortion.jpg") 

CircularSplashDistortion



from Image import * 
 
p = Image("duchamp.tif") 
p.CircularSplashDistortion(Vector(p.width/2,p.height/2), 100) 
 
p.save("CircularSplashDistortion.jpg") 

CircularWrap



from Image import * 
 
p = Image("duchamp.tif") 
p.CircularWrap(0, Vector(p.width/2,p.height/2), 50) 
 
p.save("CircularWrap.jpg") 

HoleDistortion



from Image import * 
 
p = Image("duchamp.tif") 
p.HoleDistortion(Vector(p.width/2,p.height/2), 100) 
 
p.save("HoleDistortion.jpg") 

PinchDistortion



from Image import * 
 
p = Image("duchamp.tif") 
p.PinchDistortion(Vector(p.width/2,p.height/2), 150, -2) 
 
p.save("PinchDistortion.jpg") 

ColorMap



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorMap(Image("puchamd.tif")) 
 
p.save("ColorMap.jpg") 

UnsharpMask



from Image import * 
 
p = Image("duchamp.tif") 
p.UnsharpMask(.9, 5) 
 
p.save("UnsharpMask.jpg") 

GaussianBlur



from Image import * 
 
p = Image("duchamp.tif") 
p.GaussianBlur(10) 
 
p.save("GaussianBlur.jpg") 

MedianFilter



from Image import * 
 
p = Image("duchamp.tif") 
p.MedianFilter() 
 
p.save("MedianFilter.jpg") 

MotionBlur



from Image import * 
 
p = Image("duchamp.tif") 
p.MotionBlur(15, 3.14159/6) 
 
p.save("MotionBlur.jpg") 

NoiseReduction



from Image import * 
 
p = Image("duchamp.tif") 
p.NoiseReduction(.3, .8) 
 
p.save("NoiseReduction.jpg") 

SharpenLuminance



from Image import * 
 
p = Image("duchamp.tif") 
p.SharpenLuminance(.2) 
 
p.save("SharpenLuminance.jpg") 

Bloom



from Image import * 
 
p = Image("duchamp.tif") 
p.Bloom(5, .8) 
 
p.save("Bloom.jpg") 

Edges



from Image import * 
 
p = Image("duchamp.tif") 
p.Edges(5) 
 
p.save("Edges.jpg") 

Gloom



from Image import * 
 
p = Image("duchamp.tif") 
p.Gloom(8, .9) 
 
p.save("Gloom.jpg") 

HeightFieldFromMask



from Image import * 
 
p = Image("duchamp.tif") 
p.HeightFieldFromMask(5) 
 
p.save("HeightFieldFromMask.jpg") 

Pointillize



from Image import * 
 
p = Image("duchamp.tif") 
p.Pointillize(10, 0) 
 
p.save("Pointillize.jpg") 

BlendWithMask



from Image import * 
 
p = Image("duchamp.tif") 
p.BlendWithMask(Image("puchamd.tif"), Image("pdm.tif")) 
 
p.save("BlendWithMask.jpg") 

ColorBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorBlendMode(Image("puchamd.tif")) 
 
p.save("ColorBlendMode.jpg") 

ColorBurnBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorBurnBlendMode(Image("puchamd.tif")) 
 
p.save("ColorBurnBlendMode.jpg") 

ColorDodgeBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.ColorDodgeBlendMode(Image("puchamd.tif")) 
 
p.save("ColorDodgeBlendMode.jpg") 

DarkenBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.DarkenBlendMode(Image("puchamd.tif")) 
 
p.save("DarkenBlendMode.jpg") 

DifferenceBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.DifferenceBlendMode(Image("puchamd.tif")) 
 
p.save("DifferenceBlendMode.jpg") 

ExclusionBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.ExclusionBlendMode(Image("puchamd.tif")) 
 
p.save("ExclusionBlendMode.jpg") 

HardLightBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.HardLightBlendMode(Image("puchamd.tif")) 
 
p.save("HardLightBlendMode.jpg") 

HueBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.HueBlendMode(Image("puchamd.tif")) 
 
p.save("HueBlendMode.jpg") 

LightenBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.LightenBlendMode(Image("puchamd.tif")) 
 
p.save("LightenBlendMode.jpg") 

LuminosityBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.LuminosityBlendMode(Image("puchamd.tif")) 
 
p.save("LuminosityBlendMode.jpg") 

MultiplyBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.MultiplyBlendMode(Image("puchamd.tif")) 
 
p.save("MultiplyBlendMode.jpg") 

OverlayBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.OverlayBlendMode(Image("puchamd.tif")) 
 
p.save("OverlayBlendMode.jpg") 

SaturationBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.SaturationBlendMode(Image("puchamd.tif")) 
 
p.save("SaturationBlendMode.jpg") 

ScreenBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.ScreenBlendMode(Image("puchamd.tif")) 
 
p.save("ScreenBlendMode.jpg") 

SoftLightBlendMode



from Image import * 
 
p = Image("duchamp.tif") 
p.SoftLightBlendMode(Image("puchamd.tif")) 
 
p.save("SoftLightBlendMode.jpg") 

Combinations

You can use more than one filter on a single image to combine their effects.


from Image import * 
 
p = Image("duchamp.tif") 
p.Edges(10) 
p.Pointillize(3, 0) 
p.SepiaTone(.5) 
 
p.save("Combined.jpg") 
You can also process the picture with the pixel-level techniques we used before.


import Image 
 
p = Image.Image("duchamp.tif") 
 
xmin = int(round(p.width * .25)) 
xmax = int(round(p.width * .75)) 
ymin = int(round(p.height * .25)) 
ymax = int(round(p.height * .75)) 
 
for y in range(ymin, ymax + 1): 
    for x in range(xmin, xmax + 1): 
        r, g, b = p.get(x, y) 
        p.put(x, y, 1.0-r, 1.0-g, 1.0-b) 
 
p.GaussianBlur(3) 
 
p.save("Blursquare.jpg") 
(There is currently a bug in my software that requires an image to be created from an image file for it be processed by the Python filters. This means that images made "from scratch" like the first set in the pixel tutorial cannot be filtered yet.)