Sunday, March 30, 2008

gedit Regular Expression Plugin


A friend told me that gedit was missing a regular expressions plugin that could replace. I use gedit occasionally, and so I worked on this plugin. It uses Python's good regular expression module, and supports backreferences, making it possible to do significant text processing.

This plugin is based on extensão para o gEdit by Daniel Carvalho. I fixed bugs, cleaned up the interface, moved the menuitem to the Search menu, added backreferences support, added replace all, and added an option for case-sensitivity. Also, the search mode is multiline, so ^ matches the start of a line. Download
To install, place the files in ~/.gnome2/gedit/plugins/. Then open gedit, choose Preferences from the Edit menu. On the plugins tab, you should see Regular Expression Replace in the list. Check to enable. Now, you should have a "Regular Expression" item in the Search menu. Tell me if you have any feedback.

Backreferences are very useful. In the screenshot above, I've written a regular expression for turning "one.tim" into "tim.one", and so on.

Saturday, March 22, 2008

RenameCells

Renaming files in Windows Explorer is somewhat slow - select, F2, type a new name, select the next file, and repeat. I thought it would be cool to instead use a spreadsheet interface - where pressing Enter drops you down to the next line.

So, I wrote RenameCells, a Python program for quick renaming. I also added features for batch renaming like Rename by Pattern, Replace, and Regular Expressions. You can see all of the changes in a grid before you press Rename. The grid interface also lets you copy and paste from Excel or another program. See the tutorial for information about all of this.

Update! In 2012, I moved this onto Github!

Tutorial explaining use.
Download for Windows (just unzip it and run RenameCells.exe)
Python source, cross-platform, requires wxPython.

Update -- this is now on GitHub, and I use it frequently: Downpoured at Github.

Saturday, March 8, 2008

Pythonpixels

A few days ago, I wrote Pythonpixels, an original interface for image processing. (Download).

Let's say you want to quickly prototype a new imaging algorithm. As a simple example, you are increasing the Red channel of an image by 40. Typically, this would first involve quite a bit of code, in order to gain pixel-level access to the image. Also, once testing your project, you would need to set up a test framework and enter the debug/recompile cycle.

With Pythonpixels, this whole process is as easy as typing
map:
    R=r+40
Lower-case "r" means the old red value, and "R" means the new red value. That's all there is to it. To test the effect, type this into a box, press Run, and you see the results instantly.

If you wanted to create a gradient,
loop:
    R=x+y
    G=x-y
    B=0
(It's fun to experiment making patterns this way. In the examples that come with Pythonpixels, I played around with sin and cos as well to make funky patterns.)

Also, what you type is interpretted as Python code. (Any value > 255 or < 0 is truncated for you). So, you can include complicated logic, and read the output from print statements.

If you want to do something more advanced, the entire image is exposed as imgInput. The following example makes your image all wavy.
from math import sin, cos, atan2, sqrt, pi
midx = width/2
midy = height/2
nwave = 12
imgOutput = ImageChops.duplicate(imgInput)
imgInputArray = imgInput.load()
imgOutputArray = imgOutput.load()
twopiconst = 2.0 * pi / 128.0
loop:
    newx = x + nwave*sin( y * twopiconst)
    newy = y + nwave*cos( x * twopiconst)
    if (newy>0 and newy<height and newx>0 and newx<width):
        imgOutputArray[x,y] = imgInputArray[newx,newy]


Or hue shift:
loop_hsl:
    H=h+0.2


It comes with other effects, including convolution matrices, fractals, kaleidoscope, and posterize. Data-oriented operations work very well, too, like finding pixel values, statistics, or making a histogram. Other features include pasting an image from the clipboard and batch-processing a folder of images.

Try it out! Windows Download (3.7Mb, GPL). Unzip the file and run Pythonpixels.exe. Let me know what you think, and show me scripts you come up with.

Source Python 2.5 (GPL). Requires packages tkinter, python-imaging (PIL), python-imaging-tkinter (ImageTK).

You can check out the source. 2013 Edit: moved to Downpoured at GitHub!



More details: The keyword "loop" loops through every pixel, (providing the variables x and y), and if you assign to R, G, or B, the output value at that position will be changed.

The keyword "map" sets up a precomputed table for red, green, and blue values. This makes the effect very fast, but limits what can be done - the effect cannot depend on x,y position, and hsv or hsl cannot be used.

"loop_hsv" and "loop_hsl" work in the same way as loop but are in different color spaces.

Tuesday, March 4, 2008

Maurader's Map - In Use

We've released a beta of the map, and people are starting to use it. (That's a real screenshot of the people online right now.)