Hexagon Geospatial
MENU

ERDAS IMAGINE Q&A

ERDAS IMAGINE, the world’s leading geospatial data authoring system, supplies tools for all your Remote Sensing and Photogrammetry needs.
Showing results for 
Search instead for 
Do you mean 

A Small Tutorial for IMAGINE Batch

by Technical Evangelist on ‎10-02-2015 12:34 PM - edited on ‎03-23-2016 08:08 AM by Anonymous (4,770 Views)

You can download the PDF from attachment!

 

Table of Contents

Section 1: Basics of IMAGINE Batch..................................................................................................3

  Understand IMAGINE Batch ........................................................................................................3

      A Tutorial of How to run Batch..................................................................................................3

      Customize *.bcf & *.bls file......................................................................................................7

  Automatic Batch.........................................................................................................................8

      Potential Problem for Automatic Batch.......................................................................................8

      Why that happen?..................................................................................................................8

      Solution for this Problem.........................................................................................................9

Section 2: IMAGINE Command Line................................................................................................11

  Some rules.............................................................................................................................11

      Always Use UNIX path...........................................................................................................11

      Modeler Command................................................................................................................11

      Quote() is required!..............................................................................................................12

  Run DOS Command From IMAGINE Command Line.......................................................................12

      Some Examples....................................................................................................................12

      Open IE from IMAGINE Command Line....................................................................................13

  Run Modeler.exe from IMAGINE Command Line............................................................................13

      An example.........................................................................................................................13

Section 3: Command Line in EML....................................................................................................14

  Use DOS command in EML.........................................................................................................14

  Call DOS Batch from EML...........................................................................................................15

Section 4: Run IMAGINE Command From Shell ................................................................................16

  Setup Environment Variables for ERDAS IMAGINE ........................................................................16

      Step1: Generate the .bat from IMAGINE .................................................................................16

      Step2: Modify Batch File........................................................................................................19

  Run IMAGINE Command From Shell............................................................................................21

      Run IMAGINE Command in DOS Console.................................................................................21

      Run IMAGINE Command in B-Shell (Cygwin for Windows)..........................................................22

  Run Modeler.exe.......................................................................................................................23

  Run Modeler.exe in DOS Console.............................................................................................23

  Run Modeler.exe Command in B Shell .....................................................................................24

 

Section 1: Basics of IMAGINE Batch

 

 

Understand IMAGINE Batch

 

A Tutorial of How to run Batch

There is only one way to use DOS batch: Let IMAGINE Batch to generate DOS *.bat for you.

 

Now you have 3 files: *.bls, *.bcf, *.bat

You can double-click on Export_TIFF-GeoTIFF.bat to start the process (without starting IMAGINE).

Or you can load the *.bcf from "Session->Open Batch Command File", which does the same thing.

 

 

Customize *.bcf & *.bls file

 

You may wonder that what are the *.bls & *.bcf file?

*.bcf is the real meat, which include the command lines.

*.bls contains the input file names, which allows you to process multiple input file in one batch process.

 

Below is a small tutorial:

For example you want to shift the following 2 images

d:/work/datat/2-2.img

d:/work/datat/2-3.img

 

<1> create a IMAGINE batch file (*.bcf) by yourself, let's say d:/work/datat/shift.bcf , and then edit its content like this:

/*

** IMAGINE Version 8.5 Batch Commands File

*/

variable Input User;

 

imagecommand '$(Input)' -map '$(Input.Ulx)+22.07663' '$(Input.Uly)+41.913084' 1.0000000000000000e+000 1.0000000000000000e+000 other Unknown -meter imagecommand

 

 

<2> Create a IAMGINE name file (*.bls) by yourself, let's say d:/work/datat/shift.bls   , and then edit its content like this:

Input

d:/work/datat/2-2.img

d:/work/datat/2-3.img

 

<3> Go to IMAGINE menu->Session->open Batch command files..

  locate the d:/work/datat/shift.bcf.

  click the Next;

  it will show the Input dialog, click the button called "load names from a file" (on the bottom-right corner)

  locate the d:/work/datat/shift.bls

  you should see your input filename listed in the input dialog.

  Click Finish to process the operation.

 

 

 

 

 

Automatic Batch

 

Potential Problem for Automatic Batch

 

 

For example you want to batch process NDVI. It looks very easy to do, but it is not!

 

Manual Batch always work!

 

modeler -nq $IMAGINE_HOME/etc/models/indice.pmdl -meter -state "d:/work/data/2-2.img" "d:/work/datat/d.img" Float_Single 0 1062354 2062356 1073570 2051356 Map ' ($in(3) - $in(2)) / ($in(3) + $in(2))' "None" '(($in(3) + $in(2)) ne 0)'

 

it works for single input though.

 

Automatically Batch can give you wrong command!

 

modeler -nq $IMAGINE_HOME/etc/models/indice.pmdl -meter -state "$(Input)" "$(Temp1)" Float_Single 0 '$(Input.Ulx)' '$(Input.Uly)' '$(Input.Lrx)' '$(Input.Lry)' Map '$(Output)' "None" '(($in(3) + $in(2)) ne 0)'

 

The automatically batch doesn't work. Since it recognize the NDVI equation as output, which is wrong!

 

Why that happen?

 

 

         

            Why Batch make mistake

          The reason is Batch treat the NDVI equation as filename is because “($in(3) + $in(2))” is a totally valid filename in Windows system.

                   So the   ($in(3) - $in(2))   /    ($in(3) + $in(2)) can be read as

                                      |                            |_path |

                                      |_folder name                             |_filename

      That is why Batch make this mistake, batch tool only try to interpret the argument list, nothing else.

 

      OK, We already know this

      Because of that, we make the manual batch tool, in case. And also we make it clear in our documentation:

 

        Modify commands automatically    

This option enables the Edit Commands / Create Variables panel and automatically replaces filenames with variables. Additional manual edits may also be performed.

 Examine the results of automatically modified commands carefully to ensure the resulting command and its use of variables is going to work in the way you want it to. There are often two or more ways the variables can be automated, or you may not want a particular value replaced with a variable, so the automatic modifications should always be checked.

 

Solution for this Problem

 

Use the correct format from manual batch, combine the variable from automatically batch!

 

Make your own batch

 

modeler -nq $IMAGINE_HOME/etc/models/indice.pmdl -meter -state "d:/work/data/2-2.img" "d:/work/datat/d.img" Float_Single 0 1062354 2062356 1073570 2051356 Map ' ($in(3) - $in(2)) / ($in(3) + $in(2))' "None" '(($in(3) + $in(2)) ne 0)'

 

From the original command line we can find certain strings can be replaced by variable:

"d:/work/data/2-2.img"  = "$(Input)"

"d:/work/datat/d.img" = "$(Output)"

1062354 =  '$(Input.Ulx)'

2062356 = '$(Input.Uly)'

1073570 = '$(Input.Lrx)'

2051356 = '$(Input.Lry)'

 

Then below is the final command line:

 

modeler -nq $IMAGINE_HOME/etc/models/indice.pmdl -meter -state  "$(Input)" "$(Output)" Float_Single 0 '$(Input.Ulx)'  '$(Input.Uly)'  '$(Input.Lrx)'  '$(Input.Lry)' Map ' ($in(3) - $in(2)) / ($in(3) + $in(2))' "None" '(($in(3) + $in(2)) ne 0)'

 

 

 

How to run it.

 

Step 1: Make your own batch, save the following code into a *.bcf file

 

/*

** INPUT IS DEFINED BY USER ( *.BLS)

*/

variable Input User;

/*

** OUTPUT IS DETERMINED BY INPUT.

** FOR EXAMPLE, IF INPUT = D:/DATA/X.IMG;

**              THEN OUTPUT WILL = D:/DATA/X_OUTPUT.IMG

*/

variable Output Auto "$(Input.Path)/$(Input.Root)_output.img" Delete_Before;

/*

** CALL MODELER TO CALCULATE NDVI

** NDVI EQUATION IS EMBEDDED IN THE COMMAND LINE (AS ARGUMENT)

*/

modeler -nq $IMAGINE_HOME/etc/models/indice.pmdl -meter -state  "$(Input)" "$(Output)" Float_Single 0 '$(Input.Ulx)'  '$(Input.Uly)'  '$(Input.Lrx)'  '$(Input.Lry)' Map ' ($in(3) - $in(2)) / ($in(3) + $in(2))' "None" '(($in(3) + $in(2)) ne 0)'

 

 

Step 2: Make your own input list file (*.bls)

 

Here is an example of the bls file:

Input

d:/work/data/2-2.img

d:/work/data/2-3.img

d:/work/data/2-4.img

 

 

Step 3: Use IMAGINE batch tool

 

Go to ERDAS IMAGINE Menu, Session->Open Batch Command File, load the *.bcf you just created.

Click Next;

Click “Load Names from file”, load the *.bls you just created. You should be able to see all the input filenames in the cell array.

Click Finish to process the batch.

 

 

 

How to deal with Multiple Variables

In the previous example, there is only one User variable. The next example will demo how to deal with multiple variables.

For example, you want to rescale a image from 16 bit to 8 bit. You can go to Image Interpreter->Utility->Rescale

 

 

The original command line should look like this:

modeler -nq $IMAGINE_HOME/etc/models/rescale.pmdl -meter -state "d:/work/data/quickbird_pyramids_pan.img" "d:/work/datat/out.img" 319404.460522 3318576.715953 320579.060522 3317754.215953 Map 0 0 Unsigned_8_bit 1 2 0 255 "None" Continuous "Continuous" "Continuous"

So you *.bcf file should look like this:

variable Input user;

variable Output user;

modeler -nq $IMAGINE_HOME/etc/models/rescale.pmdl -meter -state "$(Input)" "$(Output)" '$(Input.Ulx)' '$(Input.Uly)' '$(Input.Lrx)' '$(Input.Lry)' Map 0 0 Unsigned_8_bit 1 2 0 255 "None" Continuous "Continuous" "Continuous"

Your *.bls file should look like this, and different variables are separated by tab.

Input Output
d:/work/data/quickbird_pyramids_pan.img d:/work/datat/output.img

If you have more than one image, your *.bls file should follow this format:

Input Output
d:/work/Input1.img d:/work//output1.img
d:/work/Input2.img d:/work//output2.img
d:/work/Input3.img d:/work//output3.img
...
d:/work/InputN.img d:/work//outputN.img

 

 

 

 

 

Section 2: IMAGINE Command Line

 

Some rules

Always Use UNIX path

You have to make sure to use UNIX path ("\"), not Windows ("/") in your command line

 

For example the following command will not work in IMAGINE Command line:

 

exporttif -inputfilename "d:\work\data\2-2.img" -outputfilename "d:\2-2.tif" -compressionname None -tile 64 64 -photointerp RGB

 

You need to change the path:

exporttif -inputfilename "d:/work/data/2-2.img" -outputfilename "d:/2-2.tif" -compressionname None -tile 64 64 -photointerp RGB

 

 

Modeler Command

job modeler -nq quote("d:/work/gi91/root/etc/models/createfile.pmdl") -meter -state quote("d:/foo.img") "Unsigned 8 bit" Continuous 0 0 511 511 File "" 0 1 Integer "None"

Note: You have to add quote() around all the input and output file path.

 

 

Quote() is required!

 

Quote() is not only required for modeler.exe, it actually required for all IMAGINE Job command as long as there is filename involved.

 

For example, If you run the commands below in your IMAGINE Command Line, it will work!

 

viewer create at 0 48 size 600 600;

viewer truecolor quote("d:/work/data/lanier.img") rgb 1 2 3 transbackground 0;

 

 

But the commands below doesn’t work!

viewer create at 0 48 size 600 600;

viewer truecolor "d:/work/data/lanier.img" rgb 1 2 3 transbackground 0;

 

 

 

 

 

Run DOS Command From IMAGINE Command Line

 

Some Examples

 

 

Erdas Imagine Command line fully support DOS command.

Here is some examples:

 

Del:

Dos command: >del c:\test\dd.txt

 

Imagine Command:

system cmd “/c” del quote(“c:\\test\\dd.txt”) 

 

copy:

Dos command: >copy c:\test\dd.txt d:\work

 

Imagine Command:

system cmd “/c” copy quote(“c:\\test\\dd.txt”)  quote(“d:\\work”)

 

 

Note:

“/c” : will append argument to cmd

You have to use quote() and \\ for your path.

 

 

 

Open NotePad and Load some txt file

System cmd "/c" notepad quote("d:\\tree.txt")

 

 

 

 

 

 

 

Open IE from IMAGINE Command Line

 

 

Open IE, and load some html file

System cmd "/c" quote("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE") "d:/demo.html"

Or

System cmd "/c" quote("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE") "d:\\demo.html"

Or

System cmd "/c" quote("C:/Program Files/Internet Explorer/IEXPLORE.EXE") "d:/demo.html"

 

 

You can use either “\\” or “/”

 

 

 

 

 

Run Modeler.exe from IMAGINE Command Line

An example

 

For example, if you want stack the first and third layer from 2-2.img, and output to stack.img.

 

Original Command line from batch:

 

modeler -nq $IMAGINE_HOME/etc/models/layermerge.pmdl -meter -state Union None 'FLOAT RASTER n1 FILE OLD NEAREST NEIGHBOR AOI NONE EDGE FILL"d:/work/data/2-2.img"; FLOAT RASTER n2 FILE OLD NEAREST NEIGHBOR AOI NONE EDGE FILL"d:/work/data/2-2.img"; ' ignore Unsigned_8_bit "d:/work/datat/stack.img" 'n1(1),n2(3)'

 

If you copy it to a *.bcf, it will not run. You need to modify it:

 

Modified Original command line to:

 

modeler -nq "$IMAGINE_HOME/etc/models/layermerge.pmdl" -meter -state Union None "FLOAT RASTER n1 FILE OLD NEAREST NEIGHBOR AOI NONE EDGE FILL \"d:/work/data/2-2.img\"; FLOAT RASTER n2 FILE OLD NEAREST NEIGHBOR AOI NONE EDGE FILL \"d:/work/data/2-2.img\";" ignore Unsigned_8_bit quote("d:/work/datat/stack.img") "n1(1),n2(3)"

 

 

Note the following change:

from

"d:/work/data/2-2.img";

to

\"d:/work/data/2-2.img\";

 

The reason is IMAGINE command line will treat “ as the end of the string, so you need to add \ before “.

 

 

 

 

Section 3: Command Line in EML

 

EML = IMAGINE Command line.

          So just copy whatever works from IMAGIEN Command line to EML, and it should work in EML Script!

 

 

Use DOS command in EML

For example:

 

component test{

frame test

{

   title "test";

  

   button m1btn;

   button closebtn;

  

   group test

   {

         geometry 0,0,200,100;

         button m1btn

         {

               title above center "test1";

               on mousedown

               {

                     # Call DOS Command

                     system cmd "/c" copy quote("c:\\test\\dd.txt")  quote("d:\\work");

               }                

         }

        

         button closebtn

         {

               title "close";

               below m1btn;

               on mousedown

               {

                     unload;

               }

         }

   } # End of "group test"

  

} # End of "frame test"

on startup

{

   display test;

}

} # End of "component test"

 

 

 

Call DOS Batch from EML

It is very easy to do:

For example, you have a DOS batch file called c:\test.bat

 

#This is test.bat file

copy c:\dd.txt d:

 

In your Imagine command line, you can call this batch file:

job “c:/test.bat”   #use unix path style

 

Same as EML

              button btn_OK

              {

                     title above center "test1";

                     on mousedown

                     {

                           job “c:/test.bat”  #use unix path style

                     }                   

              }

 

 

 

 

Section 4: Run IMAGINE Command From Shell

 

 

Setup Environment Variables for ERDAS IMAGINE

 

In order to run IMAGINE Command outside IMAGINE Session, you need to setup all the IMAGINE environment variables in you own session.

The following two steps will generate a template batch file, which will setup all the IMAGINE environment variables outside IMAGINE session.

 

 

Step1: Generate the .bat from IMAGINE

 

Let's assume you want to generate a new image from IMAGINE Batch.

 

Create New Image...

 

 

 

Click "Batch" Button

 

Click "Use Commands as they are", and click "Next"

 

Change the time to some time in the future (make sure the batch doesn't run immediately), and click "Next"

Type in your User name & password, which has the privilege to do the Windows task scheduler. Click "Finish"

Here you go, you should be able to see all the files.

 

 

 

 

Step2: Modify Batch File

If you open the "foo.bat" file, you will see there is a lot of "Set" command, which used to setup the all the IMAGINE environment variable for the running session.

You need to remove the IMAGINE JOB part, which is highlighted in the red box.

After remove the IMAGINE JOB part, your .bat should look like this:

 

 

 

 

Now, you can save this .bat file as a template, which will setup all IMAGINE environment variables needed for processing IMAGINE JOB command.

          let's assume you save it to d:/IMGEnvSetup.bat

 

 

 

Run IMAGINE Command From Shell

 

 

Run IMAGINE Command in DOS Console

 

 

The prototype of the IMAGINE JOB command can be retrieve from Batch, or session log.

 

          Prototype from Session Log :

exporttif -inputfilename d:/work/data/2-2.img -outputfilename d:/work/datat/2-2.tif -compressionname None -tile 64 64 -photointerp RGB

 

Command Line in DOS (You can use either Windows or Unix Path)

exporttif -inputfilename "d:\work\data\2-2.img" -outputfilename "d:\2-2.tif" -compressionname None -tile 64 64 -photointerp RGB

or

exporttif -inputfilename "d:/work/data/2-2.img" -outputfilename "d:/2-2.tif" -compressionname None -tile 64 64 -photointerp RGB

 

 

 

 

Run IMAGINE Command in B-Shell (Cygwin for Windows)

Similar to DOS console!

You need to setup the ERDAS IMAGINE environment variables first from DOS console, then launch the B-shell environment!

 

Since the Cygwin B-shell can inherit all the environment variables from DOS console, you can access all the IMAGINE command.

You can type "env" in B-shell to verify if you inherit all the IMAGINE environment variables.

 

 

 

Run Modeler.exe

 

Run Modeler.exe in DOS Console

 

Modeler.exe is different from other IMAIGNE commands, so it deserve a special treatment.

Since Modeler need the IMAGINE session log to running, so it is impossible to directly run modeler in DOS Console.

 

You have to write all your command line into *.bcf file, since directly calling modeler.exe from command line will not work.

Below is an example of the *.bcf file.

 

 

 

Make sure you have *.bcf, *.bls file ready before run this command:

batchprocess -bcffile "d:\foo.bcf" -blsfile "d:\foo.bls" -logfile "d:\foo.log"

 

 

Run Modeler.exe Command in B Shell

 

       You also need to create an empty *.bls file

Now you can run this in B-shell:

batchprocess -bcffile "d:\foo.bcf" -blsfile "d:\foo.bls" -logfile "d:\foo.log"

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Contributors