Nip2
thumb|200px|nip2-7.12.2 on 64-bit Ubuntu
Greenspun's Tenth Rule of Programming : Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
nip2 aims to be about halfway between Excel and Photoshop. You don't directly edit images --- instead, like a spreadsheet, you build relationships between objects.
You enter formula (or select menu items) to describe how to make a new object from some of the objects you already have. nip2 keeps track of these relationships: if you make a change anywhere, nip2 automatically recalculates anything affected by the change.
You can load a 500MB image, rotate it by 12 degrees, and immediately view the transformed image. This is because only the pixels needed to paint the display are actually calculated. You can add a slider, link it to the rotation, and as you drag the slider you can see your 500MB image spinning on the screen.
You can apply a filter to the rotated image, zoom in to check the effect on individual pixels, crop out a small section of the filtered image and save the cropped area to disc. All this happens pretty much instantly and with only a few mouse-clicks. The final save may take a little while (since nip2 does actually have to calculate some pixels then), but it will only calculate the pixels it absolutely has to (it will not rotate the entire 500MB image, for example).
If you do something useful, you can turn it into a reuseable menu button with three mouseclicks.
- right-click on the titlebar of the column you want to reuse
- select Make Column into Menu Item
- a dialog pops up that lets you set the name and toolkit
- click Menuize.
You can use any image-processing operation in the VIPS operation database, including operations you have written yourself.
nip2 includes its own programming language. It's a higher-order lazy pure functional programming language, with classes. nip2 includes an integrated editor, compiler and debugger. Almost all of the menus/buttons/etc. are implemented using this extension language. See the Programming chapter in the nip2 manual if you're interested.
Very handy if you need to process a lot of files. You can group objects in nip2 and process them all with one click, or you can use nip2 as a programming language and write scripts which can be run by other programs. We have a website which uses nip2 as the backend to generate images.
The name nip2
is a bit odd.
It started out in about 1990 as an image viewer for VIPS files under SunView called vf
. We added a programming language linked to the VIPS library and called it ip
, for Image Processing. It first switched to Motif, then when our lab dropped Sun and went Linux we rewrote for GTK and changed the name to nip
, for new ip. Most recently we rewrote again for GTK2, so we now have nip2.
The HOWTO page lists a couple of on-line examples, including one on Colour calibration with nip2.
nip2 comes with a set of example workspaces. The Examples page summarises them.
If you do something useful in a column of operations, right-click on the column title bar, select Make Column Into Menu Item, and select Menuize on the dialog that pops up. A new menu item will appear which will load a fresh copy of your column every time you click it.
You can use nip2's programming language to make new operations by glueing existing operations together. For example, you could click Toolkits / Edit Toolkits and type:
Sobel im
= abs (a - 128) + abs (b - 128)
{
filter_sobel = Matrix_con 1 128 [[/1,_2,_1],_[0,_0,_0],_[-1,_-2,_-1|1, 2, 1], [0, 0, 0], [-1, -2, -1]];
a = conv filter_sobel im;
b = conv (rot270 filter_sobel) im;
}
Click File / Process Text to get nip2 to compile this definition and a new menu item will appear called Sobel. Select an image, click on Sobel and you should see a filtered image.
The real menu items nip2 loads have a couple of extra wrinkles to make them work with groups of images and to present a nice menu text, but they are very similar.
You can run nip2 as a command-line program: this can be very handy for batch processing. Type nip2
--help
for help, but for example you could enter
nip2 -e "2 + 2"
and it will (after a longish pause) print
4
Obviously you'd usually use it for something more complex than that.
nip2 -e "99 + Image_file argv?1" fred.jpg -o result.png
Load argv1 (fred.jpg), add 99, output to result.png.
nip2 -e "Matrix [[/1,2],[4,5|1,2],[4,5]] ** -1" -o poop.mat
Invert the 2x2 matrix and write the result to poop.mat.