Batchmake slicer: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
===BatchMake in Slicer===
===BatchMake in Slicer===
BatchMake has been integrated in Slicer since version 3, then highly improved in [http://wiki.slicer.org/slicerWiki/index.php/Documentation-3.4 version 3.4]. A "Batch Processing" category can be found in the list of Slicer modules.<br>
BatchMake has been integrated in Slicer since version 3, then highly improved in [http://wiki.slicer.org/slicerWiki/index.php/Documentation-3.4 version 3.4]. The [http://www.slicer.org/slicerWiki/index.php/Documentation-3.4#Batch_processing Batch Processing] category can be found in the [http://www.slicer.org/slicerWiki/index.php/Documentation-3.4#List_of_Modules Slicer modules list].<br>
There are 4 modules into the Batch Processing subsection: [http://wiki.slicer.org/slicerWiki/index.php/Modules:GaussianBlurBatch-Documentation-3.4 Gaussian Blur BatchMake], [http://wiki.slicer.org/slicerWiki/index.php/Modules:RegisterImagesBatch-Documentation-3.4 Register Images BatchMake], [http://wiki.slicer.org/slicerWiki/index.php/Modules:EMSegmentBatch-Documentation-3.4 EMSegment BatchMake] and [http://wiki.slicer.org/slicerWiki/index.php/Modules:ResampleVolumeBatch-Documentation-3.4 Resample Scalar Volume BatchMake]. All the Batch modules are internally calling Slicer modules, respectively [http://wiki.slicer.org/slicerWiki/index.php/Modules:GaussianBlur-Documentation-3.4 Gaussian Blur], [http://wiki.slicer.org/slicerWiki/index.php/Modules:RegisterImages-Documentation-3.4 Register Images], [http://wiki.slicer.org/slicerWiki/index.php/Modules:EMSegment-Simple EMSegment Simple] and [http://wiki.slicer.org/slicerWiki/index.php/Modules:ResampleVolume-Documentation-3.4 Resample Scalar Volume].<br>
There are 4 modules into the Batch Processing subsection: [http://wiki.slicer.org/slicerWiki/index.php/Modules:GaussianBlurBatch-Documentation-3.4 Gaussian Blur BatchMake], [http://wiki.slicer.org/slicerWiki/index.php/Modules:RegisterImagesBatch-Documentation-3.4 Register Images BatchMake], [http://wiki.slicer.org/slicerWiki/index.php/Modules:EMSegmentBatch-Documentation-3.4 EMSegment BatchMake] and [http://wiki.slicer.org/slicerWiki/index.php/Modules:ResampleVolumeBatch-Documentation-3.4 Resample Scalar Volume BatchMake]. Each Batch module internally calla a Slicer module, respectively [http://wiki.slicer.org/slicerWiki/index.php/Modules:GaussianBlur-Documentation-3.4 Gaussian Blur], [http://wiki.slicer.org/slicerWiki/index.php/Modules:RegisterImages-Documentation-3.4 Register Images], [http://wiki.slicer.org/slicerWiki/index.php/Modules:EMSegment-Simple EMSegment Simple] and [http://wiki.slicer.org/slicerWiki/index.php/Modules:ResampleVolume-Documentation-3.4 Resample Scalar Volume].<br>
<br>
<br>
The ultimate strenght of batch processing is to run automatically multiple modules multiples times with multiple parameters on multiple inputs on multiple machines. <br>
Batch processing allows you to automatically run on multiple machines multiple modules multiple times with multiple parameters on multiple inputs. <br>
Since [http://wiki.slicer.org/slicerWiki/index.php/Documentation-3.4 Slicer 3.4], you can easily transform any Slicer modules to support batch processing. Only minor changes in the module XML file are needed, no code rewriting.<br>
Since [http://wiki.slicer.org/slicerWiki/index.php/Documentation-3.4 Slicer 3.4], you can easily transform any Slicer modules to support batch processing. Only minor changes in the module XML file is needed, no code has to be written specifically for a Batch module.<br>
In this tutorial we will introduce you with BatchMake in Slicer and guide you step by step to batch process your data. We will also explain how you can create your own BatchMake module in Slicer.<br>
In this tutorial we will introduce you with BatchMake in Slicer and guide you step by step to batch process your data. We will then explain how you can create your own BatchMake module based on a Slicer module.<br>


===How to run a BatchMake module locally?===
===How to run a BatchMake module locally?===
Line 11: Line 11:
|[[Image:GaussianBlurBatchMake.png|thumb|300px|Gaussian Blur BatchMake GUI]]
|[[Image:GaussianBlurBatchMake.png|thumb|300px|Gaussian Blur BatchMake GUI]]
|}
|}
In this section, we will see how to run locally (on your machine) a Gaussian Blur filter on a single image with different sigma values.
In this section, we will see how to run on a local machine a Gaussian Blur filter. For a single input, multiple output will be generated, one for each sigma value.
*Launch Slicer
*Launch Slicer
*Open the "Gaussian Blur BatchMake" module located in "Batch Processing"
*Open the "Gaussian Blur BatchMake" module located in "Batch Processing"
*By setting Sigma minimum, Sigman maximum and Sigma step, you change the number of times the Gaussian Blur module will be called with a different sigma. If Sigma minimum, maximum and step are respectively set to 1, 10 and 1; Gaussian Blur will be run 10 times, with a sigma varying from 1 to 10.
*Set <b>Sigma Minimum</b>, <b>Sigma Maximum</b> and <b>Sigma Step</b>, it changes the number of times the Gaussian Blur module will be called with a different sigma. If Sigma minimum, maximum and step are respectively set to 1, 10 and 1; Gaussian Blur will be run 10 times, with a sigma varying from 1 to 10.
*Then fill "Data directory", a directory containing images to blur
*Then select a directory for <b>Data directory</b>. The directory shall contains the input images to blur.
*Change the mask (wildcards) to select the images to blur based on their filenames.
*Define a mask (using wildcards) to select the images to blur based on the filename and/or extension. Each image fitting the mask requirements will be processed separately.
*Check "Recursive" if you want to recursively apply the "Data file" mask in the "Data directory".
*Check <b>Recursive</b> if you want to recursively apply the "Data file" mask in the "Data directory".
*Choose an output directory where all the result images will be saved in for "Output directory"
* Select a directory for <b>Output directory</b>. The ( nb_input * (sigma_max - sigma_min) / sigma_step ) result images will be saved in that directory.
*Make sure the "Run using Grid/Condor" checkbox is unchecked to run the module locally
*Make sure the checkbox <b>Run using Grid/Condor</b> is unchecked as we want to run the module locally
*Press apply to launch the processing
*Click <b>Apply</b> to launch the processing.
Note: The inputs of the Gaussian Blur filter are the files found in the input directory. If Sigma minimum, Sigma maximum and Sigma step are respectively set to 1, 10 and 1, then 10 files will be created for each input file. For example, if 3 files in the input directory  
Note: The inputs of the Gaussian Blur filter are the files found in the input directory. If Sigma minimum, Sigma maximum and Sigma step are respectively set to 1, 10 and 1, then 10 files will be created for each input file. For example, if 3 files in the input directory  
  imageX.mha, imageY.mha and imageZ.mha  
  imageX.mha, imageY.mha and imageZ.mha  
match the "Data file mask", (i.e. all three matching *.mha); after the module is executed the output directory will contain:  
match the <b>Data file mask</b>, (for example all three matching *.mha); then the output directory will contain after the module is executed :  
  imageX-1.mha, imageX-2.mha ... imageX-10.mha,
  imageX-1.mha, imageX-2.mha ... imageX-10.mha,
  imageY-1.mha, imageY-2.mha ... imageY-10.mha,
  imageY-1.mha, imageY-2.mha ... imageY-10.mha,
  imageZ-1.mha, imageZ-2.mha ... imageZ-10.mha
  imageZ-1.mha, imageZ-2.mha ... imageZ-10.mha
<center>
{|
{|
|[[Image:GaussianBlurBatchMakeModuleInput.png|78px|thumb|Input images]]
|[[Image:GaussianBlurBatchMakeModuleInput.png|center|78px|thumb|Input images]]
|[[Image:GaussianBlurBatchMakeModuleOutput.png|800px|thumb|Output images]]
|[[Image:GaussianBlurBatchMakeModuleOutput.png|center|800px|thumb|Output images]]
|}
|}
</center>
===How to run Register Images on a Condor grid===
===How to run Register Images on a Condor grid===
In this section, we will see how to register - on different machines - multiple moving images to a single fixed image .  
In this section, we will see how to register multiple moving images with a single fixed image. The computation will be done on several machines using Condor.  
We will assume that Condor has been already installed on your machine(s) and works properly. You must have created and configured a condor user account on your machine, the condor scripts generated by BatchMake will be executed by the condor user ( +Owner = condor ).  
Condor must be already installed on your machine(s) and work properly. You must have created and configured a condor user account on your machine, the condor scripts generated by BatchMake will be executed by the condor user ( +Owner = condor ).  
*Start Slicer as a regular user, there is no need to be a condor user.
*Start Slicer ( as a regular user, there is no need to be a condor user ).
*Open the "Register Images BatchMake" module located in "Batch Processing"
*Open the [http://www.slicer.org/slicerWiki/index.php/Modules:RegisterImagesBatch-Documentation-3.4 Register Images BatchMake] module located in <b>Batch Processing</b>
<center>
{|
{|
|[[Image:RegistrationBatchMake-Selection.png|thumb|center|400px|Selection of the Register Images Batch module]]
|[[Image:RegistrationBatchMake-Selection.png|thumb|400px|Selection of the Register Images Batch module]]
|[[Image:RegisterImagesBatchMakeModule-RigidRegistration.png|thumb|center|400px|Register Images Batch GUI]]
|[[Image:RegisterImagesBatchMakeModule-RigidRegistration.png|thumb|400px|Register Images Batch GUI]]
|}
|}
*
</center>
 
* In the IO section, select an input <b>Fixed Image</b> file. All the moving image will be registered with it.
* Then select a directory for <b>Moving Image Directory</b>. The moving images can be in its subdirectories.
* Select a mask to filter the moving images from the <b>Moving Image Directory</b>. If the moving images are in sub-directories, the mask shall be a relative path. The sub-directories can be wildcarded as well as the file names( i.e. "Patient*/Image*.mha")
* Select an output directory for <b>Resample Image</b> where the output images will be saved.
* A mask describes how to generate the filename of the output images based on the input parameters. The XML variable names can be used by enclosing their name into a dollar sign and braces, i.e. "Registered-${rigidMaxIterations}-${fixedImage}.
* Fill the other sections according to your needs or let them by default.
* The <b>Advanced Rigid, Affine and BSpline Registration</b> parameters use a min/max/step mechanism. This allow you to automatically vary the module parameters. By defining a min, max and step inputs for a single parameter, the Register Image module will be run (max-min)/step times for each inputs with a different Rigid Max Iterations(or Affine or BSpline) parameter each time. In our example, Register Image module will be run integer(200-10/50)=3 times.
===How to vary the module parameters ?===
===How to vary the module parameters ?===


===How to write your own Batch Processing module ?===
===How to write your own Batch Processing module ?===
The BatchMake modules running on Condor don't support the <image> tags in the module XML files. Slicer pass <image> arguments to the modules the memory address where the image is loaded and not the filename of the image.  as <im they must be changed into <file> or <directory>+<string>. Share
The BatchMake modules running on Condor don't support the <image> tags in the module XML files. Slicer pass <image> arguments to the modules the memory address where the image is loaded and not the filename of the image.  as <im they must be changed into <file> or <directory>+<string>. Share

Revision as of 16:22, 8 May 2009

BatchMake in Slicer

BatchMake has been integrated in Slicer since version 3, then highly improved in version 3.4. The Batch Processing category can be found in the Slicer modules list.
There are 4 modules into the Batch Processing subsection: Gaussian Blur BatchMake, Register Images BatchMake, EMSegment BatchMake and Resample Scalar Volume BatchMake. Each Batch module internally calla a Slicer module, respectively Gaussian Blur, Register Images, EMSegment Simple and Resample Scalar Volume.

Batch processing allows you to automatically run on multiple machines multiple modules multiple times with multiple parameters on multiple inputs.
Since Slicer 3.4, you can easily transform any Slicer modules to support batch processing. Only minor changes in the module XML file is needed, no code has to be written specifically for a Batch module.
In this tutorial we will introduce you with BatchMake in Slicer and guide you step by step to batch process your data. We will then explain how you can create your own BatchMake module based on a Slicer module.

How to run a BatchMake module locally?

Gaussian Blur BatchMake GUI

In this section, we will see how to run on a local machine a Gaussian Blur filter. For a single input, multiple output will be generated, one for each sigma value.

  • Launch Slicer
  • Open the "Gaussian Blur BatchMake" module located in "Batch Processing"
  • Set Sigma Minimum, Sigma Maximum and Sigma Step, it changes the number of times the Gaussian Blur module will be called with a different sigma. If Sigma minimum, maximum and step are respectively set to 1, 10 and 1; Gaussian Blur will be run 10 times, with a sigma varying from 1 to 10.
  • Then select a directory for Data directory. The directory shall contains the input images to blur.
  • Define a mask (using wildcards) to select the images to blur based on the filename and/or extension. Each image fitting the mask requirements will be processed separately.
  • Check Recursive if you want to recursively apply the "Data file" mask in the "Data directory".
  • Select a directory for Output directory. The ( nb_input * (sigma_max - sigma_min) / sigma_step ) result images will be saved in that directory.
  • Make sure the checkbox Run using Grid/Condor is unchecked as we want to run the module locally
  • Click Apply to launch the processing.

Note: The inputs of the Gaussian Blur filter are the files found in the input directory. If Sigma minimum, Sigma maximum and Sigma step are respectively set to 1, 10 and 1, then 10 files will be created for each input file. For example, if 3 files in the input directory

imageX.mha, imageY.mha and imageZ.mha 

match the Data file mask, (for example all three matching *.mha); then the output directory will contain after the module is executed :

imageX-1.mha, imageX-2.mha ... imageX-10.mha,
imageY-1.mha, imageY-2.mha ... imageY-10.mha,
imageZ-1.mha, imageZ-2.mha ... imageZ-10.mha
Input images
Output images

How to run Register Images on a Condor grid

In this section, we will see how to register multiple moving images with a single fixed image. The computation will be done on several machines using Condor. Condor must be already installed on your machine(s) and work properly. You must have created and configured a condor user account on your machine, the condor scripts generated by BatchMake will be executed by the condor user ( +Owner = condor ).

  • Start Slicer ( as a regular user, there is no need to be a condor user ).
  • Open the Register Images BatchMake module located in Batch Processing
Selection of the Register Images Batch module
Register Images Batch GUI
  • In the IO section, select an input Fixed Image file. All the moving image will be registered with it.
  • Then select a directory for Moving Image Directory. The moving images can be in its subdirectories.
  • Select a mask to filter the moving images from the Moving Image Directory. If the moving images are in sub-directories, the mask shall be a relative path. The sub-directories can be wildcarded as well as the file names( i.e. "Patient*/Image*.mha")
  • Select an output directory for Resample Image where the output images will be saved.
  • A mask describes how to generate the filename of the output images based on the input parameters. The XML variable names can be used by enclosing their name into a dollar sign and braces, i.e. "Registered-${rigidMaxIterations}-${fixedImage}.
  • Fill the other sections according to your needs or let them by default.
  • The Advanced Rigid, Affine and BSpline Registration parameters use a min/max/step mechanism. This allow you to automatically vary the module parameters. By defining a min, max and step inputs for a single parameter, the Register Image module will be run (max-min)/step times for each inputs with a different Rigid Max Iterations(or Affine or BSpline) parameter each time. In our example, Register Image module will be run integer(200-10/50)=3 times.

How to vary the module parameters ?

How to write your own Batch Processing module ?

The BatchMake modules running on Condor don't support the <image> tags in the module XML files. Slicer pass <image> arguments to the modules the memory address where the image is loaded and not the filename of the image. as <im they must be changed into <file> or <directory>+<string>. Share