Skip to content

Batch_Processing_with_Nip2

John Cupitt edited this page Mar 29, 2017 · 1 revision

title: Batch Processing with Nip2 permalink: /Batch_Processing_with_Nip2/

Appendix A Batch processing on the command line.

app:batch

A.1 Batch Processing in Windows

The nip software gives a user access to a large number of image processing functions that can be run on single or groups of images. However, when simple operations, such as cropping, need to be performed on large groups of images it is normally faster to produce a small command line program to process all the images at once. These batch functions work by directly calling the VIPS image processing libraries, rather than going through the nip graphical user interface. In the Linux and Mac distribution of our software these VIPS image processing libraries are readily accessible, however in the Windows distribution the process is more complex. This section describes how to set up your windows machine so that VIPS command line batch functions can be used. The process will involve downloading files, unpacking compressed files, moving files around your system and creating and editing a few text files. Each stage will be described in details, but a reasonable level of computing knowledge will be assumed. If you are currently running a dual boot Windows/Linux machine and changing from one to the other to capture and batch process you should be able to follow the instructions below.

A.1.1 Download and Install Files

Begin by downloading the most recent versions of the following files and pieces of software: (NB the file names given below are correct at the time of writing, if newer versions of the software are available they will have similar names but the numbers will be different.)

nip2' for windows:' this can be downloaded from the VIPS web site[#note90\ 1]. You will need the latest Windows binary, for example, nip-7.10.9.zip. Versions of nip2 older than 7.8.14 may not contain all of the files you need for batch processing images in Windows.

MinGW and MSYS These are the programs that will allow you to run a command line terminal in Windows. They can both be downloaded from the MinGW download page[#note91\ 2] on the MinGW web site. There are a large number of files listed in a table on this page and you will need to download two of them, both of which will be in the section of the table indicated as current. The first will be listed under [current][MSYS][bin][MSYS-1.0.10.exe] and the second will be listed under [current][MinGW][bin][MinGW-3.1.0-1.exe].

If you do not already have it installed you will probably also have to download and install a piece of software to deal with compressed or zipped files[#note92\ 3].

A.1.2 Install MinGW

This package can be installed by DLMB on the downloaded file in a file-manager window[#note93\ 4], for example MinGW-3.1.0-1.exe. You will be asked several questions during the installation process, it is recommended that you just except all of the default settings. The rest of the instructions will assume that you have excepted the defaults, if you have made any changes, such as installation path, you will just need to make similar adjustments in the following instructions.

A.1.3 Install MSYS

This package can be installed by DLMB on the downloaded file, for example MSYS-1.0.10.exe. Again just except all of the initial default settings. Once the first part of the installation has been completed a dos command window will open up to continue the installation. You will be asked three simple questions. Firstly you will be asked if you would like to continue, type y and hit [Return] to continue. The second question will ask you if you have MinGW installed, again type y and hit [Return] to continue. The final question will ask you where MinGW has been installed, if you have accepted all of the defaults type c:/mingw and then hit [Return]. The installation process is now basically finished, you will need to press another key to close the dos window and then return to the original installation window. Here you given the option to read some files, leave the options selected if you want to. CLMB on [Finish] to close the window and complete the process. A blue M icon, for MSYS will have appeared on your desktop, DLMB on the icon to open up a terminal window. Starting the terminal for the first time organises your basic user settings. You can now close the terminal window and continue.

A.1.4 Install Nip

For more detail on how to install nip2 see chapter [#chap:install 4]chap:install.

A.1.5 Setting up MSYS

MSYS basically sets up a Linux like environment on your PC, if you would like to learn more about it please visit the MinGW web site[#note94\ 5]. When you DLMB on the MSYS icon a terminal window will open, which can be used to run command line functions similar to those used in Linux. In order to use the system to run VIPS batch functions a few adjustments need to be made. The first step is to copy the entire nip2 directory[#note95\ 6] into your MSYS home area, which should be c:/msys/1.0/home/xxxx, where xxxx is your user name. The instructions below will use the user name joe, please replace it with your own user-name.

Edit /etc/profile

Open up a normal windows file manager window and move through your system to show the contents of your MSYS directory, this will probably be c:/msys/1.0/. Here you will see the directory structure that your MSYS system will use. Move into the c:/msys/1.0/etc directory and find the file called profile. Open up the profile the in your text editor of choice[#note96\ 7], for example CRMB on the file, select [Open] and then follow the options to allow you select Wordpad/Notepad from a list of available applications. Add the following line to the bottom of the file and save the file and close the text editor.

  • . ∼/.bashrc

The last few lines should now be:

  • alias clear=clsb cd "$HOME" . ∼/.bashrc

A.2 Create your .bashrc file

[#note97\ 8] The .bashrc file is used to add extra directories to the system path, i.e. where it looks for programs, to produce this file you will need to use a text editor and a terminal window. Start up a terminal window, msys, xterm, etc. Then type in the following command and hit [Return] to check what the current system path is:

  • echo $PATH
  • In Windows the output will probably be,
  • .:/usr/local/bin:/mingw/bin:/bin:/c/ WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/ System32/Wbem
  • Or in Linux, something like
  • /home/joe/bin:/usr/local/bin:/usr/bin: /usr/X11R6/bin:/bin:/usr/games: /opt/gnome/bin:/opt/kde3/bin: /usr/lib/java/jre/binbut

Check it just in case. Move to a file manager window, or open a new one, and move to show the contents of your home area, i.e. c:/msys/1.0/home/joe, /home/joe. Create a new text file in your home area[#note98\ 9] and call it tmp.txt. DLMB on this new file to open it up in a text editor and type in the following lines:

  • export VIPSHOME=/home/joe/nip-7.10.9
  • syspath=.:/usr/local/bin:/mingw/bin: /bin:/c/WINDOWS/system32:/c/WINDOWS: /c/WINDOWS/System32/Wbem
  • export PATH=$VIPSHOME/bin:$syspath

Make sure that you insert your own user-name, the correct nip2 version number and that the syspath is the same as the one you that was shown in the terminal with the echo $PATH command, alter the text where required. Save the file and then close the text editor. Move back to the terminal and type in the following commands, hitting the Return key in between:

  • cd
  • mv tmp.txt .bashrc

After entering the two commands close the terminal. You should now be ready to run batch scripts.

A.3 Running batch processes

The following batch files are available in the standard distribution of nip2:

  • batch_crop
  • batch_rubber_sheet
  • batch_image_convert
  • batch_srgb2mono
  • light_correct

Following a successful setup, as described, any of these files can be run on the command line in a terminal[#note99\ 10], by typing sh followed by the name of the batch file, and then the required arguments. If you run any of the batch files without arguments some information will be displayed explaining what further information is required. For example running the following command:

  • sh batch_crop
  • Will produce text similar to:
  • usage: batch_crop image1 image2 ...
  • writes: cr_image1, cr_image2, ...
  • batch_crop uses VIPS to crop a group of image files. The position and size of the crop is defined by the values given for , , and .

A.4 Example

For this example we are going to assume a user has captured a set of images and a grey target. The user wants to apply a fixed crop to all of the images, (in order to remove some black pixels that their capture system leaves around each image), and then apply a light correct, using the grey image, (to correct for any inhomogeneity of their lighting). For this example we will say the group of images are named, image_1.v, image_2.v ... and grey.v, and that each image is 600x300 pixels and the user wants to crop 5 pixels from each edge. The following commands could be used:

  • From any directory in your system:
  • sh batch_crop 5 5 590 290 /full_directory_path/*.v
  • Or the following command if you are in the directory containing your images:
  • sh batch_crop 5 5 590 290 *.v

This will produce a new set of cropped images, cr_image_1.v, cr_image_2.v ... and cr_grey.v, in the same directory as your original images. The next stage is to light correct this new set of images using the cropped grey image, cr_grey.v:

  • From any directory in your system:
  • sh light_correct /full_directory_path/cr_grey.v /full_directory_path/cr_im*.v
  • Or the following command if you are in the directory containing your images:
  • sh batch_light_correct cr_grey.v cr_im*.v

This will produce your final set of correct images, ic_cr_image_1.v, ic_cr_image_2.v, etc, in the same directory as your original images.

A.5 Creating new batch files

If you want to see how the batch files work just open them up in a text editor and if you want further information regarding the functions used, or why they are used please refer to other documentation posted on the VIPS website[#note100\ 11] or email the users-group[#note101\ 12].


[#text90 1] http://www.vips.ecs.soton.ac.uk/

[#text91 2] http://www.mingw.org/download.shtml

[#text92 3] One of the more common pieces of software of this type is WinZip and a free evaluation version of their software can be downloaded from there website. NB: this functionality is already built in to Windows XP.

[#text93 4] see section [#sec:filemanager B.1]sec:filemanager for more information of filemanagers

[#text94 5] http://www.mingw.org

[#text95 6] The directory that was created from the downloaded nip2 file, currently nip-7.10.9

[#text96 7] Either of the basic Windows text editors, Wordpad or Notepad will be fine, using Word will complicate things do to file formats.

[#text97 8] If you are working in Linux you may already have a .bashrc file, in this case just edit the file to ensure the listed lines are included.

[#text98 9] CRMB on an empty part of the file manager window and then select [New][Text Document] in windows, or [Create New][File][Text file] in linux, from the menu.

[#text99 10] You can use the cd command to move between folders in the terminal, for example cd /home/joe/nip-7.10.9 will take you to /home/joe/nip-7.10.9, cd on its own will take you to your hone directory and cd .. will move you up one directory. The command pwd can be used to display which directory you are in and finally the ls command can be used to show the contents of the current directory. NB: If you are using Windows and your main hard-disk is C: then you can move into the C: directory in the MSYS terminal by typing cd /C

[#text100 11] http://www.vips.ecs.soton.ac.uk

[#text101 12] http://www.jiscmail.ac.uk/lists/vipsip.HTML

Appendix B File-managers, xtrems, etc.

chap:othersoftware

B.1 Filemanager and creating your own folders

sec:filemanager When you start to work with a computer you will want to organise all of the images and documents that you produce; you can achieve this by creating new folders within your computers fileing structure. An easy way to do this is by using a Filemanager program. Within Linux the easiest filemanager to use is normally a program called Konqueror; which can be normally be opened by CLMB on one of the house icon on the Taskbar at the bottom of the screen. Windows and Mac OS have there own filemanagers, but they general all perform im a similar manner. Within this document any reference to a filemanager will relate to the use of Konqueror, however you can use a different filemanager if you wish. In Linux to create your own folder or directory (/home/general/'X' where X is the name of your directory) using a 'Filemanager': the Edit heading on the menu bar [2] and then CLMB on the entry 'Create new' and then again on 'Directory', from the menus which will appear. * [Filemanager][Edit: Create new: Directory] A box will appear on the screen, in this box enter the name you want for your new folder and then press return. If you wish to change the name of the folder then simply CRMB over the folder and CLMB over the option 'properties' which appears in the drop down menu. The name of the folder can then be changed in the window that will appear. CLMB within the file name field, type in the new name and then press return.

B.2 Xterm: Easy access to a command line terminal

sec:xterm When using Linux, many programs are run by entering a command directly through a command line. There are many different types of command line windows; this document, for reasons of simplicity is going to use one, the xterm window. Below is a description of how to set up an icon on your desktop, which will open an xterm window. Figure 1: Screenshot of an xterm window, displaying the contents of the directory /home/joe; where joe is the user name and ducio is the name of the computer. * CRMB over an empty area of the background. * Select [Create new]:[Application] from the menus that appear. * This will open up a small window entitled Properties for Program.desktop - KDesktop,with a text box containing, Application * CLMBover the text box and change the text to read,xterm. * CLMB on the Execute tab, near the top of the window. * CLMB over the text box under the Program Name: heading and then enter xterm * CLMB on [OK] * An icon will then appear on you desktop with the word xterm under it. The picture used for the icon is the default icon for applications. If you wish to change the picture you can do so as follows: * Reopen the Properties window: CRMB over the icon and chose properties from the menu. * Ensure that the General tab is selected. * The CLMB on the picture of the icon to the left of the text box in which you entered xterm before. * This will open up another window containing a large selection of alternative pictures, scroll down until you find one that you like, select it by CLMB on it, then CLMB on [OK], to close the window. * Then CLMB on[OK] in the Properties window to close it. * Your new chosen picture should now be in place on the desktop. * You can now run an xterm window by CLMB on your new icon.

Clone this wiki locally