Monday, 16 May 2011

Using groups in nip2

nip2 lets you group objects so you can use the menus to operate on many images at the same time. This post will try to explain how to use the grouping system and how it works.

Overview

Let's start with a quick example. Launch nip2, click File / Open, and navigate to a directory of images. Click on the first, shift-click on the last and click Open. You can open up to about 500 images at once, but please don't for this example, five is plenty. The main window should now look something like this:
Right-click on the row button and click Ungroup to open the group. This creates a new row for every group element. It will be unbearably slow for 500 images, but for five it works fine.
Remove the extra rows you made (click on A2, shift-click on the last row, click Edit / Delete). Now click Filter / Convolution / Custom Blur/Sharpen, and set the parameters to be a Gaussian blur. You could pick any other operation, or any combination of operations.
Finally, right-click on the row button for the processed group and select Save As. Enter a filename of the form fred001.jpg and nip2 will save the processed images to fred001.jpg, fred002.jpeg, and so on.

Grouping and ungrouping

There are several ways to form groups. You can make them directly in the file chooser as above, but you can also form them from objects already in the workspace. Click on the first row, shift-click on the last, and select Edit / Group.
Groups can contain any other object, even other groups.

You can also form groups by typing. Enter (for example):
Group [1 .. 4]
You can turn lists into groups and back again, see Object / List to Group and friends. Once a group has been turned to a list, you can use any of the usual list-processing operations to operate on them.

Saving a group will save each of the group elements in turn. You can also ungroup with Edit / Ungroup, though that won't work very well for large groups. For large groups it's usually better to turn the group to a list, then pick out a particular element with list index. This is easy to type:
A15.value?1
Will extract element 1 from a group.

Processing

Almost all of nip2's menu items will automatically loop over groups, as we saw in the introductory example. Almost all of the built-in operations will automatically loop as well. For example, try typing:
12 + Group [1 .. 4]
and you'll see
Group [13, 14, 15, 16]
The system is very general. Going back to the example in the screenshot above typing A15 + 99 gives this:
Groups can have NULL elements, meaning 'skip this item'. This is handy in complex workspaces where not every group element may be valid. If you operate on a pair of groups and one contains a NULL element at some point, the result will also be NULL at that point.

If one group is longer than the other, the results is as long as the shortest group.

A convenient way to develop a workspace is to start out processing a single image, then when everything is working, edit the first row to drop in a group instead.

Limitations

Very large groups don't work very well: you'll find you start to run out of file descriptors if you have more than about 500 source images open at once. For very large jobs you'll be better off using nip2's command-line interface to run a workspace over a set of files.

For technical reasons, nip2's list processing operations don't work well with groups. You'll find you can't type hd A1, where A1 is a group of lists, for example. Fixing this would take a large rewrite of nip2's programming language, sadly.

You also can't use Region on groups, annoyingly. This means that if your workspace includes any regions dragged out with the mouse, you won't be able to just drop a group in. Use Image / Crop instead.

No comments:

Post a Comment