Using Shell scripting to lessen typing

From MIPAV
Jump to: navigation, search

Using shell scripts to reduce the amount of repetitive work is a common reason for writing a script. When best used, several small scripts that work in concert can reduce the amount of typing required and the amount of time needed and can automate tasks.

The following example uses a Windows command shell to illustrate how you can shorten the number of keystrokes required. In this case, you would write a batch file to load a levelset VOI into an image.

{| border="1" cellpadding="5" |+ |- |
@echo off
rem -- %1 is the full path to the image file, though not
rem -- the file itself; we assume there to be a *01.dcm
rem -- file to exist in this directory.

rem -- VOI is assumed to be in the same directory with name
rem -- levelset1.xml

./mipav -i %1\*01.dcm -v %1\levelset1.xml
|}

More efficient and more useful, starting MIPAV with multiple images is easily done in a simple script. Here is how it is done in BASH:

{| border="1" cellpadding="5" |+ |- |
#! /bin/bash
# argument 1 is the file (with wild-cards) we want to open
# arg 1 must be escaped (with quotes) to allow the shell to send
# the wildcards unmolested to the script. Otherwise, the shell
# will try to expand the shorthand. This has a different effect.

LISTING=`ls $1` # Generate the file listing
MIPARGS=
# For each file in the listing, prepend it with '-i' and
# the filename, then follow it with all the previous
# files.
for FS in $LISTING;
do
MIPARGS=" -i $FS $MIPARGS";
done

# start MIPAV:
./mipav $MIPARGS
|}

Although this script doesn't include the line ./mipav $MIPARGS with a "&" to run MIPAV in the background, it could have. This would have the effect of exiting the script with MIPAV in the background; as it is, the script does not exit-and return control to you at the command line-until MIPAV exits.

Scripting toolbar
[ 1]Not all MIPAV algorithms are scriptable.
[ 2]Exit( ) end is auto added when the script is running from the command line with -hide key.
[ 4]"do_output_new_image boolean true" will indicate that the result image appears in a new image frame
[ 5]This saves only the image with margins, not the post-blurred image.