Showing results for 
Search instead for 
Do you mean 

Batching and Parallel Processing of Supervised Classification

by Technical Evangelist ‎07-27-2016 08:10 AM - edited ‎07-27-2016 08:14 AM (1,413 Views)


How to Batch a Supervised classification in IMAGINE?



Performing supervised classification on numerous input image files is often a tedious and time consuming process.

However, assuming that the input imagery is radiometrically similar (i.e. it is derived from the same sensor type and has been processed to remove atmospheric and other scene to scene variations, such as by running it through the ATCOR 3 for ERDAS IMAGINE module to convert to reflectance) it is a simple task to use the ERDAS IMAGINE tools to batch the job of applying a standard signature file (or files) to multiple input image files in order to produce classified / thematic output categorized data layers. This process can even be broken down into jobs which can be parallel processed on a single computer or submitted to a distributed processing environment such as Condor.

This white paper takes you through the steps necessary to create an ERDAS IMAGINE Batch Command File for executing multiple supervised classification jobs.



Obviously you will need to have your input multispectral imagery available for processing.

You will also need at least one signature file (*.sig) produced using the ERDAS IMAGINE Signature Editor which has been trained with examples of all the classes to be extracted based on an image with the same number of bands as the data to be batch classified. As mentioned above training signatures are generally only transportable between input images if scene to scene variations have been removed. So it generally advisable to have normalized all scene data using something similar to ATCOR3 for ERDAS IMAGINE so that all input imagery (including the image used to train and create the signature file) have had atmospheric and illumination effects corrected out to scene reflectance.


Setting up the processes


  1. Start by filling in the Supervised Classification dialog as you would if you were going to classify the first of the input images you wish to process. Specify the input image name, the name of the signature file you are going to apply, an output image name and any other parameters you wish to use for all the images that are going to be processed.



  1. Instead of clicking OK, as you would normally do to immediately run the one defined supervised classification process, click Batch. Batch Command Editor dialog window will open.



  1. As it currently stands the syntax would run the supervised classification program (classifysupervised.exe) using the fixed input image name, output name and other parameters. So if we want to iterate the program across multiple inputs, outputs, etc., we need to convert those fixed file names into variables instead. So the next task is to define the required input and output variables. Click on the Edit button next to Variables row. The Variable Editor window will open.



  1. The first thing that needs to be variabalized is the input image name so that we can feed in more than one image. So in the Variable Editor window click Add and change the default NEW_VARIABLE name to a meaningful value such as Input.



The inputs to the Input variable will be defined in a later step.


  1. We also need to be able to produce one output thematic (classified) image per input multispectral image, so we also need a variable for the output file name. Click Add again and change this variable NEW_VARIABLE to another meaningful string such as Output.
  2. Since Output is going to be used to name the output thematic images it is good practice to set up an automated naming scheme that is meaningful to you (such as being able to identify which output thematic image relates to which input image, or to identify how many runs of the classification succeeded). To do this change Output’s Type from User to Auto.



  1. In the Pattern section click Set… which will bring up the Edit Replacement Pattern dialog.




Here is where we can set up a pattern for the naming of the output. Perhaps we want to use the input files root name with a modifier at the end of it such as “_classified” and then have the same file type extension as the input. For example when image1.img is fed into the classifer we want the output to be automatically named image1_classified.img.


  1. In the Templates area click on $(<variable>.<function>) to add it into the Pattern area as shown above.
  2. Click in the Pattern area and instead of <variable> string past the Input variable so that the Pattern syntax becomes $(Input.<function>)



  1. Click in the Pattern area and instead of <function> string past the Root from Functions list so that the Pattern syntax becomes $(Input.Root). This syntax will now automatically take the file name root of each input.



  1. Place the cursor in the Pattern area after the $(Input.Root) string and type the modifier you want such as “_classified”.



  1. Repeat steps 11 to 13, but rather than using Root pick Ext (extension) from the Functions list to complete a Pattern as shown below.



  1. Click OK in the Edit Replacement Pattern
  2. You may also wish to specify a particular directory to write all Output files into so in the Pattern area of the Variables tab type in the desired output directory path before the pattern, such as d:/output/ (this directory should already exist before you attempt to execute the batch commands).



Optionally, you might want to consider turning Delete Before Processing on. If you do so any file that already exisits will be deleted before the batch command is run. This can be useful if, for example, the batch has to be re-run for some reason after a failed attempt which created unwanted output files. Otherwise leave this option off.


  1. Having defined your variables you can now substitute them into the appropriate places in the supervised classification command syntax. Activate the Batch Command Editor
  2. Use the mouse cursor to carefully select the currently fixed input file name and path. Do not select any spaces before or after the string.



  1. With the input name/path string selected go to the Variable Editor dialog window. Select Input variable and click Insert.



  1. Similar to step 19 select the currently fixed output file name and path. Do not select any spaces before or after the string.


  1. With the output name/path string selected go to the Variable Editor dialog window. Select Output variable and click Insert.



  1. Optionally you might also wish to variabilise the currently fixed file name for the signature to use if you intend to use different signature files with different input images. However for the purposes of this example we will assume that the same signature file is being used to classify all input images and so we will leave that section of the command syntax as it is.

Click Close in Variable Editor dialog.


  1. On the Batch Command Editor window click the Save icon at the lower right of the dialog. This enables us to create a Batch Command File (*.bcf) which can be re-used at later dates to perform the same command syntax batch jobs without needing to repeatedly go through the process shown in steps 1 to 21. Specify a location and file name for the BCF file and click OK in Save Batch Commands
  2. On the Batch Command Editor click Add files…
  3. In the resulting Select Batch Files navigate to the directory with the input images to be iterated on by the batch command and select them. Click OK.



All Input files and automatically created Output will appear in Batch Command Editor window.




  1. Click Submit… button in Batch Command Editor window. Submit dialog will open.



  1. If you wish to use multiple cores on the current computer (either Now or Later At… a specific time/date) for parallel processing increase the value shown in the Simultaneous Processes field to signify how many individual batch jobs you wish to be running simultaneously. For example, if you have an 8 core computer (and have sufficient licences available to run the requisite number of simultaneous processes) you might increase the count to 8 (or perhaps 7 if you wish processing power to be left over for other tasks beside the ERDAS IMAGINE jobs). In the example below it has been set to run 3 commands simultaneously.



  1. Alternatively, if you have a Condor distributed processing network configured you may wish to select the Start Distributed Processing option instead which will submit all batch jobs to the Condor controller node to manage.
  2. Click OK.
  3. If you opted to Start Processing Now you will see an ERDAS IMAGINE Process List / progress meter come up showing how four jobs are being simultaneously executed, as specified at step 26.



This particular batch queue had 9 jobs (9 input image files to be classified). As seen below all 9 jobs completed successfully with a maximum of 3 jobs running at any given time.




Using the Batch Command File


At step 22 of the above process a Batch Command File (*.bcf) was created. These BCF files can be used at a later time to repeat the same type of commands on a new set of input files without needing to go through the same set up process. To re-use a BCF file follow these general steps:


  1. From the main ERDAS IMAGINE ribbon interface select the File > Batch > Open Batch Command File



  1. In the file chooser navigate to and select the previously saved Batch Command File and click OK.
  2. In the Batch Command Editor window the previously defined and variabalized batch command will be displayed and no further editing of the command itself is necessary (but can be applied if desired).


If it is desired to use a different signature file a couple of different options are available:

  1. The BCF file itself is a simple text file – so before opening it at step 1 you could use a text editor to open the .bcf file, edit the path and file name to the new signature file, save the .bcf file and then open the edited .bcf file at step 1.
  2. Alternatively you can turn the signature Input argument into a Variable instead in Variable Editor window.