Meet the GIMP #38: A Python in a Barrel

Posted in Development, Graphics on April 22, 2009


Meet the GIMP #38: A Python in a Barrel

Will this title scare more people away than catch by curiosity? Who knows…..

The barrel distortion that gave me such problems last week is removed by using a built in filter for correcting (or simulating) lens distortions. You can find it in the image menu at Filters/Distorts/Lens Distortion.

As I have a lot of images with this error, I go out and write a special Python plugin to do this task. It’s not as complicated as it seems - I have a good template and the Web and Gimp give a lot of useful information. You can find the scripts used in this episode here on the Download Page

EDIT: If you are using Windows and GIMP 2.4.x, have a look here for informations about setting up Python for GIMP.
EDIT2: This is supposed to be even easier.

This is the finished Python program:

#!/usr/bin/env python

import math
from gimpfu import *

def remove_barrel_distortion(img, drw):

img.disable_undo()

layer_corr = drw.copy(True)
layer_corr.mode = NORMAL_MODE
layer_corr.name = "Barrel corrected"
img.add_layer(layer_corr, -1)

pdb.plug_in_lens_distortion(img, layer_corr, 0.0, 0.0, -12.0, 0.0, 0.0, 0.0)

img.enable_undo()
gimp.displays_flush

register(
"remove_barrel_distortion",
"Removes the barrel distortion of a Sanyo CA65",
"",
"Rolf Steinort <info @meetgimp.org>",
"public domain",
"2008",
"<image>/Filters/Distorts/B_arrel distortion removal CA65",
"RGB*, GRAY*",
[],
[],
remove_barrel_distortion)

main()

You find a similar program in this posting. There I have torn it apart and described all the parts. The Python for GIMP documentation and this website can be helpful.

Don’t forget the challenge! Make a monochrome image and post it in our meetthegimp.org photogroup at 23 and be sure to use the tag “mtg-monochrome”. The challenge ends March 31 1600GMT and I’ll draw a winner by random choice.

Watch Video Watch Video on External Site

Tags: Python, Design, GIMP, Meet the GIMP, plugin, Broadcasting, Screencasts, Development, barrel distortion, lens distortion, writing filters, writing plugins