A Simple Command Line Argument Parser

Please use this identifier to cite or link to this publication: http://hdl.handle.net/10380/3258
This document describes the implementation of a simple command line argument parser using the Insight Toolkit ITK. Such a parser may be useful for use in the examples of the ITK. This paper is accompanied with the source code.
minus 1 Dataset (125Kb)
plus Automatic Testing Results by Insight-Journal Dashboard on Tue Apr 12 12:33:02 2011 for revision #1
starstarstarstarstar expertise: 5 sensitivity: 5

minus Much needed... but duplicates existing ITK functionality by Rupert Brooks on 2011-06-28 12:43:55 for revision #3
starstarstarstarstar expertise: 3 sensitivity: 4.5

The authors provide additionnal ITK classes for reading/writing Dcm/Tiff from MEVIS


The authors provide additionnal ITK classes for reading/writing Dcm/Tiff from MEVIS


The authors provides a test file wich I've direclty used with some MEVIS data I had.

Open Science:

The authors provide the source code + a test file.

The authors did not provide dataset to test the code


The authors nicely describe how to use its code. However, It took me some time before being able to compile the code.

I am under Windows7 64bit, VS 2008

I've used:

gdcm 2.0.10 (static)
ITK 3.20 (shared)

WARNING some version of gdcm does not compile or does not compile together with ITK.

gdcm in shared library did not compile

1. To compile ITK, I had to manually edit the properties of the ITK project : itkTestDriver



a. Additionnal Depedencies:



b. Additionnal Library Directories:

add library directory of TIFF library


c. Add an include file into MevisDicomTiffImageIO.h:

#include "gdcmByteSwapFilter.h"

Maybe not the perfect one but I took one where gdcm::DataSet was used if you do not include it leads to the following error:

itkMevisDicomTiffImageIO.h(152) : error C2039: 'DataSet' : is not a member of 'gdcm'


2. To compile the itkMevisTest.cxx file:

I had again to manually edit the VS project the same way as presented above.

Open source Contributions:

As I've had issues with gdcm library, it tooks me two days to make it compile

Code Quality :

I did not extensively review the code, but it seems to be clean C++ of high quality.

Free comment :

This tool is usefull when you are dealing with MEVIS data and should be incorporated into ITK library if possible (issue with gdcm compilation).



minus Great addition! by David Doria on 2011-04-13 09:00:48 for revision #3
starstarstarstarstar expertise: 3 sensitivity: 4.5

In almost every example in ITK there are very confusing uses of the command line arguments. For example, in CannyEdgeDetectionImageFilter.cxx there is a section:

  if( argc > 3 )


    variance = atof( argv[3] );



  if( argc > 4 )


    upperThreshold = atof( argv[4] );



If the arguments are changed, every index must be manually updated. This also leads to very easy logic errors. With this proposed parser, the above section can be changed to simply:

float variance = 1.0;

parser->GetCommandLineArgument("-variance", variance);

float upperThreshold = 2.0;

parser->GetCommandLineArgument("-upperThreshold", upperThreshold);


and the input can be changed from 

CannyEdgeDetectionImageFilter brain.png 2.3 4.5

to a much more clear:

CannyEdgeDetectionImageFilter -input brain.png -variance 2.3 -upperThreshold 4.5


This will certainly improve the clarity of the examples enormously!


Open Science:

Reasonable tests are provided, and the documentation is very clear.


The code compiles and runs correctly on my system.

Use of Open Source Software:

A brief discussion of why to use this instead of a large library for command line parsing is provided and convincing.

Open source Contributions:

The code is very straight forward and easy to use.

Free comment :

I would like to see this code added to the ITK toolkit.

Add a new review
Quick Comments
Comment by Marius Staring yellow
Just comitted
Comment by Ariel Hernán Curiale yellow
Hi Marius, I fixed a bug in my code. I didn't know that you have another version. My version dosen't have that method. Also, your method dosen't print the parameters.
Take a look of the output of my code and yours:
-------- My code ------
Command Line Arguments:
--GWidthBM: 3
--alpha: 250
--blockSizeBM: 10
--downSampleBM: 6
--elementPerLine: 3
--epsilon: 1e-5
--espGrid: 5
--fieldSampleRate: 5 5 5
--fixedManualSeg: /Volumes/Uva/DatosEco/DatosRioHortega/DatosCartesianos/PhantomIM_0001A/conCompLog/myo_IM_0001A_1_Axial_PhantomCompLogSSD_TrueField.nrrd
--forceCollapse: 1 1 0
--inputVolume: /Volumes/Uva/DatosEco/DatosRioHortega/DatosCartesianos/PhantomIM_0001A/conCompLog/IM_0001A_1_Axial_PhantomCompLogSSD_TrueField.nrrd
--labelMask: 3
--lambda: 0.2
--lambdaBM: 0.5
--maxIt: 25
--maxItBM: 5
--maxItDemons: 10 10 10
--maxRmsE: 0.7 0.4 0.2 0.01
--metricType: SSD
--movingManualSeg: /Volumes/Uva/DatosEco/DatosRioHortega/DatosCartesianos/PhantomIM_0001A/conCompLog/myo_IM_0001A_5_Axial_PhantomCompLog.nrrd
--multiResolutionItScale: 2
--multiResolutionScale: 10
--newDirection: -1 0 0 0 1 0 0 0 1
--newDirection2: -12.1 0 0 0 1 0 0 0 -122.0
--numberChecker: 8
--numberOfLevels: 4
--numberTrheads: 1
--outputCk: outputCk.txt
--radiusDilateMask: 10
--relaxFact: 0.8
--searchSizeBM: 3
--sigmaBM: 3
--sigmaDef: 2
--sigmaUp: 8
--sliceCollapse: 104
--stepAffinelength: 0.01 10
--steplength: 0.01 40
--tmovedImage: 5
--transformType: VBST
--trueFieldName: /Volumes/Uva/DatosEco/DatosRioHortega/DatosCartesianos/PhantomIM_0001A/SSD_TrueField_Axial.nrrd
--verbosity: 1
--volume: /Volumes/Uva/DatosEco/DatosRioHortega/DatosCartesianos/DatosNrrd/IM_0001A.nrrd

-------- Your code ------

Comment by Marius Staring yellow
Hi Ariel,

Thanks for your comments. Note that we keep a latest version at

We have a function PrintAllArguments() there.

We did not notice printing problems or issues with negative numbers. Can you give some details?

Regards, Marius
Comment by Ariel Hernán Curiale yellow
Hi, I've fixed a bug to allow negative numbers and print properly. If you want I could share the code with you.
Comment by Ariel Hernán Curiale yellow
Hi, great work. I've added the functionality to print the arguments.
This is the code if you want to add to your class:

::PrintSelf(std::ostream & os, Indent indent) const
<< indent << "Command Line Arguments:"
<< std::endl;

for( ArgumentMapType::const_iterator it = this->m_ArgumentMap.begin(); it!=this->m_ArgumentMap.end(); ++it)
os << indent << it->first;

if(this->m_Argv.size() > it->second + 1 && this->m_Argv[ it->second + 1 ].substr(0,1) != "-")
os << ":";
for(unsigned int i=it->second +1; i < this->m_Argv.size() && this->m_Argv[i].substr(0,1) != "-";i++)
os << " "<< this->m_Argv[i];
os << std::endl;

<< indent << "----------------------"
< }

Download All
Download Paper , View Paper
Download Source code

Statistics more
Global rating: starstarstarstarstar
Review rating: starstarstarstarstar [review]
Code rating: starstarstarstarstar
Paper Quality: plus minus

Information more
Categories: Data, Generic Programming
Keywords: command line parsing, tool
Toolkits: ITK, CMake
Export citation:


Linked Publications more
A Label Geometry Image Filter for Multiple Object Measurement A Label Geometry Image Filter for Multiple Object Measurement
by Padfield D., Miller J.
Anisotropic Fast Marching in ITK Anisotropic Fast Marching in ITK
by Mirebeau J.

View license
Loading license...

Send a message to the author
ISSN 2327-770X
Powered by Midas