ITK/FAQ: Difference between revisions

From KitwarePublic
< ITK
Jump to navigationJump to search
(→‎Using Insight: Big cleanup.)
Line 280: Line 280:


== Platform-specific questions ==
== Platform-specific questions ==
=== Build->Rebuild All in MS VC++ reloads all projects ===
=== How do I avoid multiple prompts to reload all projects in Microsoft Visual Studio? ===
When performing a "Rebuild All" from Microsoft Visual C++, every project prompts the user for a reload (and there are hundreds of projects).
When the CMake source changes, you may see multiple prompts to reload many projects.


DO NOT USE "Rebuild All" or "Batch Build". Use the following recommended procedure.
DO NOT USE "Rebuild All" or "Batch Build". Use the following recommended procedure.
Line 289: Line 289:
This can also be done from the command line like this: msdev ITK.dsw /MAKE "ALL_BUILD - Debug" /REBUILD
This can also be done from the command line like this: msdev ITK.dsw /MAKE "ALL_BUILD - Debug" /REBUILD


=== Highlighting .txx files in Visual Studio ===
=== How do I fix Visual Studio 7 (2002) Compiler Issues? ===
 
How can I get Visual Studio to do syntax hightlighting in the files with extension .txx ?
 
There are four ways to do this:
 
# The <b>WRONG</b> way
# The <b>DANGEROUS</b> way
# The <b>NICE</b> way
# The <b>OPEN SOURCE</b> way
# The <b> SUPER EASY </b> way using VC9
 
==== The WRONG way ====
 
The <b>WRONG</b> is to mark the .txx files as "Compilable". This is WRONG because the .txx files are only intended to be compiled when they are invoked from a .cxx file. Doing this will result in errors such as the ones reported in.
 
  http://public.kitware.com/pipermail/insight-users/2005-December/015847.html
 
which after many email exchanges were identified
 
  http://public.kitware.com/pipermail/insight-users/2005-December/015905.html
 
==== The DANGEROUS way ====
 
The <b>DANGEROUS</b> way is to make changes in the Windows Registry entries of Visual Studio.
 
http://public.kitware.com/pipermail/insight-users/2005-November/015785.html
 
You should avoid doing this since it brings *Bad Karma*. Once you touch the Windows Registry, the consequences will follow you in the afterlife (regardless of whether you believe in the afterlife or not).
 
==== The NICE way ====
 
This thread for VS8 does not work:
http://public.kitware.com/pipermail/insight-users/2005-November/015786.html
 
However, this thread will work for VS8.
http://www.itk.org/pipermail/insight-users/2006-May/018061.html
 
Go the OPEN SOURCE way.
 
==== The OPEN SOURCE way ====
 
STOP Using the Visual Studio editor, behave as a real programmer and use a decent source code editor such as VIM or EMACS. You can configure these editors to be the default editor used by the Visual Studio IDE.
 
=====The SUPER EASY way using VC9=====
 
Open Tools>Options
 
Navigate under the Text Editor>File Extension Tree
 
Type txx in the extension field
 
Choose Microsoft Visual C++ from the drop down combo box
 
Hit Apply
 
DON'T tick the box saying "Map extension files to:"
 
Restart Visual Studio
 
Enjoy color-coded debugging of your template definitions.
 
=== Borland 5.5 Compiler Issues ===
To build Insight using the (free) Borland 5.5 compiler:
 
# Get the Borland compiler from http://www.borland.com and install it
# Run cmakesetup and select the Borland Makefiles in the "Build For:" drop down.
# Set the CMAKE_BUIlD_TYPE to MinSizeRel. This is required so that the Borland linker will stay below its size limit which is arounbd 35 meg for a tds file.
 
=== Borland 5.6 Compiler Issues ===
Well ITK simply does not support this compiler at all.
 
=== Windows + FLTK: unresolved external symbol TrackMouseEvent ===
This error is due to changes in FLTK and it is totally unrelated to ITK. The error only appears in ITK demo applications that are using FLTK for GUI.
 
The library "comctl32" must be added to the link command line.
 
You can solve this by editing the CMake file: CMake/Modules/FindFLTK.cmake and around line 39 add the comctl32 library.
 
After the change the lines should look like:
 
IF(WIN32)
  SET( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
ENDIF(WIN32)
 
This is already fixed in the CVS version of CMake FindFLTK.cmake.
 
The CMake version 1.6 will have this issue solved.
 
===Mac OS X ===
 
====Highlighting .txx files in Xcode====
 
Xcode does not recognise the .txx file extension as C++ code, and so one does not see proper syntax highlighting.  You can correct this on a per-file basis by choosing Format > Syntax Coloring > C++.
 
====Getting Shared Libraries to work====
There is a problem with the Xcode 1.5 tool chain that prevents shared libraries from working.  Fortunately, the Mac folks have fixed the problem.  You have to update Xcode, the compiler and as much stuff as possible, and it will work again, after you start from a clean build. If gcc -version reports anything less than 3.3 build 1671, then you should update the compiler. From the Apple developers download http://developer.apple.com/macosx/download/ you have to login to get the November2004GCCUpdater.
 
If you are using Xcode 2.0 or later, there should be no problem.
 
====Under Mac OS X, when I try to run a program that builds successfully, the window is displayed but I can't interact with it.====
 
This is caused by the fact that the application needs to be registered with the window manager for correct operation.  There is an additional step that needs to be performed ''after'' the link step, in order to add the required resources to the binary.  This can be done with a simple:
 
% /Developer/Tools/Rez Carbon.r -o myapp
 
For apps built with FLTK, you can use:
 
% /Developer/Tools/Rez /usr/local/include/FL/mac.r -o myapp
 
Here is an example of adding a custom command to do this automagically in your `CMakeList.txt` file:
 
IF(APPLE)
  FIND_PROGRAM(APPLE_REZ Rez /Developer/Tools)
  ADD_CUSTOM_COMMAND(TARGET MyApplication
    POST_BUILD
    COMMAND ${APPLE_REZ}
    ARGS ${FLTK_INCLUDE_DIR}/mac.r -o MyApplication)
ENDIF(APPLE)
 
'''Note:''' This is ''not'' required for applications build against X libraries; only for Carbon-based applications.  If you have built FLTK for X rather than Carbon, the above does not apply.
 
(Gavin Baker, 7-May-2004)
 
=== How to set Windows DLL's on the Path ===
 
==== In Windows 95 and 98 ====
 
# Click on the "Start" button on the task bar.
# Click on the "Run..." button
# Type "sysedit".  This is the editor of the system files, including the "autoexec.bat"
# If you have already a PATH variable, then add the directory where the ITK DLLs are to that list. Use ";" as separators
# If you don't have a PATH variable.... well... add one and put your directory there. It should look like
 
  PATH=C:\itkbin\bin\Release\
 
==== In Windows XP Method A ====
 
# Go to "Control Panel"
# Select "System",
# Take the "Advanced" tab
# Click on the button "Environment Variables" on the bottom,
# Select "PATH"
# Add the full directory where you have your ITK .dlls. Pay attention to whether they are in the Release or Debug subdirectories.
 
==== In Windows XP Method B ====
 
# Right-Click on "My Computer" ( a popup menu should appear, the last option on it is "properties")
#Select "properties" a new popup window appears with some tabs on it.
# Select the tab "Advanced"
# At the bottom you will se a button called "Environment Variables". Click on it.
# A new popup window appears with a small browser with the list of environment variables. In this browser you will see the list of environment variables.
# Select "path" and click on the "edit" button. A small new popup appears with two text fields: "Variable name" and "Variable value".
# Go to the "Variable value" field, move to the end, add a ";" separator and type the directory where you have the VTK or ITK Dlls.
# Add another ";" separator and type the directory where you have the ITK Dlls.
# Click on "OK" to close the "Edit User Variable" window.
# Click on "Ok" on the "Environment Variables" window.
# Click on "Ok" on the "System Properties window".
# Take a deep breath, cross you fingers and try to execute your program again.
 
==== Maximum Length for the Windows PATH variable ====
 
* Limitation:
  8191 characters (Windows XP)
  2047 characters (Windows 2000 or NT 4.0)
 
* Solution for a given executable:
  copy the dlls into the executable directory
 
* General solution:
  Control Panel
  '- System
      '- Advanced
            '- Environment variables
                '- System Properties
                    '- System Variables
                        '- New
  In the popup window:
  Variable name: ITKDebug
  Variable value: c:/cygwin/home/Sylvain/ITKDebug/lib/debug
  Click OK
  Scroll to 'Path' and click 'Edit'
  In Variable value, add at the end of the line (click on the 'End' key): %ITKDebug%
  Repeat this operation for every library path...
  until you reach the maximum path length. ;-)
 
* Solutions from http://support.microsoft.com/default.aspx?scid=kb;en-us;830473
 
The limitation applies to the command line, individual environment variables (such as the PATH variable) that are inherited by other processes, and all environment variable expansions. If you use Command Prompt to run batch files, this limitation also applies to batch file processing.
 
# Modify programs that require long command lines so that they use a file that contains the parameter information, and then include the name of the file in the command line.
# Modify programs that use large environment variables so that the environment variables contain less than either 2047 or 8191 characters (as appropriate to your operating system).
## Use shorter names for folders and files.
## Reduce the depth of folder trees.
## Store files in fewer folders so that fewer folders are required in the PATH environment variable.
## Investigate possible methods that you can use to reduce the dependency of PATH for locating .dll files.
 
=== Visual Studio 6 Compiler Issues ===
 
ITK requires service pack 5 or higher to build with Visual Studio 6.  However, there are still some code patterns occasionally encountered when using ITK code that cause an INTERNAL COMPILER ERROR.  Here is a minimal example of code that reproduces the ICE:
 
<pre><nowiki>
namespace N { template <class T> struct C {}; }
template <class T> struct A
{
  // Inside this template we refer to another template in another namespace.
  void m(const N::C<int>&);
};
 
// Now declare a class template using a non-type template parameter.
template <unsigned int V> struct B;
</nowiki></pre>
 
The above code results in an ICE reported from line 1794 of msc1.cpp.
The work-around is to use a typedef to refer to the other template:
 
<pre><nowiki>
namespace N { template <class T> struct C {}; }
template <class T> struct A
{
  typedef N::C<int> NCint;
  void m(const NCint&);
};
template <unsigned int V> struct B;
</nowiki></pre>
 
Here is another example causing a crash in the same place:
 
<pre><nowiki>
// Create a class template that has type and non-type arguments with defaults.
template <class T=int, int N=1> class A {};
 
// Require the compiler to deduce the arguments for a specific instantiation.
template <class T, int N> void f(A<T,N>) {}
void g() { f(A<int,1>()); }
</nowiki></pre>
 
The work-around is unforunately to not have the first default template argument:
 
<pre><nowiki>
template <class T, int N=1> class A {};
template <class T, int N> void f(A<T,N>) {}
void g() { f(A<int,1>()); }
</nowiki></pre>
 
There are other code patterns that cause the same error.  If you find one please try to produce a minimal example and add it to this page.
 
==== Visual Studio 6 Compiler : Why you should not use it ====
 
Visual Studio 6 is becoming a really old compiler if you are thinking of using it for your project be ready to bang your head against the wall.
Anyway if you have to use it, here are some fixes to the compiler include file (mostly STL related):
 
* [http://www.dinkumware.com/vc_fixes.html Fixes for Library Bugs in VC++ V5.0/V6.0]
* [http://www.acceleratedcpp.com/details/msbugs.html Known problems in using the Microsoft Visual C++ compiler, version 6.0]
 
==== Visual Studio 6 Compiler : Freezing CMake Configuration ====
 
There exists a known Problem when trying to configure ITK with CMake for VC++ 6.0 without Service Pack 6 installed, apparently mainly on multicore systems. During Configuration CMake will freeze while running compiler tests at random points, because the VC++-Compiler stops responding. Service Pack 6 fixes this problem and should be installed anyway, since a lot of other bugs are fixed as well. Anyway, if possible a more recent version of Visual Studio should be used (see above).
 
=== Visual Studio 7 .NET 2002 Compiler Issues ===


The Visual Studio 7.0 compiler is more similar to the version 6 compiler than the version 7.1 compiler from the C++ conformance perspective.  While it does not crash as frequently as version 6, there are some code patterns that still cause an INTERNAL COMPILER ERROR.  Here is one example:
The Visual Studio 7.0 compiler is more similar to the version 6 compiler than the version 7.1 compiler from the C++ conformance perspective.  While it does not crash as frequently as version 6, there are some code patterns that still cause an INTERNAL COMPILER ERROR.  Here is one example:
Line 585: Line 326:
</nowiki></pre>
</nowiki></pre>


 
=== How do I fix prolems with MipsPro Compilers (7.3.3.1m and 7.4.2m) on IRIX? ===
=== Visual Studio 8 .NET 2005 Issues ===
 
==== Deal with Runtime Exceptions in a Managed C++ Windows Forms Application ====
 
When such an application uses ITK, it produces runtime exceptions, such as 'System.TypeInitializationException' or memory assertions.
 
To prevent this, put classes that use ITK into a separate CLR library. Do not make your Forms Application dependent on ITK, but on this library only. You can follow these steps:
# Create C++ CLR Windows Forms Application,
# Add to your solution a new Visual C++ CLR Class Library; the benefit of a CLR library is that you don't need to include headers in your Forms Application to use classes from the library, hence your Forms Application may know nothing about ITK
# Set in this library all ITK directories, include, libraries as you would do so in a not managed application (C/C ++ -> General->Additional Include Directories, Linker->General->Additional Library Directories and Linker->Input->Additional Dependencies); if you have problems, use CMake to generate settings for a not managed application using some sample code and copy these settings
# Add a reference to this Class Library in your Forms Application
# In your Class Library, wrap ITK processing into managed classes, you can then use these classes from your Forms Application
# Remember about linking your Class Library with ITK against matched runtime libraries (C/C++ -> Code Generation -> Runtime Library should match in both your Class Library and ITK project properties)
# In your Forms Application, you can use VTK to visualize results
## VTK can be used in a Forms Application without putting it into a separate class library
## you need to change /clr:pure to /clr (Project Configuration Properties->General->Common Language Runtime support) in the Forms Application
## your Class Library can export ITK processing results to VTK using itk::VTKImageExport and vtkImageImport (use ConnectPipelines to link these two - the usage and the method's implementaion can be found across ITK sample applications)
## if your Class Library uses e.g. vtkImageImport in a public interface, remember about including the directive #pragma make_public(vtkImageImport) in your sources
 
You should keep in mind that ITK processing in a CLR application is very slow, even when compiled without debug information (using Release configuration). It's best to create even one more library, pure C++ DLL, no CLR, put there the whole ITK processing pipeline and expose only output filters. This way you may have:
 
#C++ DLL, no CLR, in which you have defined the whole ITK pipeline
#C++ library, with CLR (if you need it), that depends on ITK, VTK and the first library. It connects the output of the first library to the input of itk::VTKImageExport, which in turn is connected to vtkImageImport as described above.
#C++ Windows Forms application CLR, which depends only on VTK and on the second library.
 
Using the above 3-part configuration instead of CLR-only components, has shortened the processing time in my application from about 10 minutes to 20 seconds(!).
 
(Tadeusz Dracz, Oct-4-2006)
 
=== MipsPro Compilers (7.3.3.1m and 7.4.2m) on IRIX ===


There have been reports of problems building ITK on IRIX platform.  Here are the compiler flags that are used to build ITK and submit nightly dashboard results.  SGI Flags for both 7.3.3.1m and 7.4.2m compilers that are working for the kraepelin.uiowa nightly builds.
There have been reports of problems building ITK on IRIX platform.  Here are the compiler flags that are used to build ITK and submit nightly dashboard results.  SGI Flags for both 7.3.3.1m and 7.4.2m compilers that are working for the kraepelin.uiowa nightly builds.

Revision as of 19:14, 9 June 2012

General information and availability

Do I need VTK to build ITK ?

With the default configuration, ITK does not require VTK. However, some optional modules (ITKVTKGlue) do require VTK.

ITK does not provide any visualization functionalities. Applications requiring visualization should implement those functionalities from internal code or libraries like OpenGL, GLUT or VTK.

What 3D file formats can ITK import and export?

The following table identifies the file formats that ITK can read/write via a factory mechanism based on the file extension (itk::ImageIOFactory). Some proprietary files format are only imported. More information on ITK File Formats is available, including data types supported.

A very nice tool for viewing all of these images is ImageViewer which can be found in the ITKApps repository.

File Format Read/Write Import
Analyze 7.5 AnalyzeImageIO
BMP † BMPImageIO
DICOM GDCMImageIO Using DicomImageIO is backward compatible, but user should prefer GDCMImageIO
GE 4x GE4ImageIO
GE 5x GE5ImageIO
GE Advantage Windows GEAdwImageIO
Gipl (.gipl) GiplImageIO
IPLCommon IPLCommonImageIO
JPEG † JPEGImageIO
MetaImage (.mha/.mhd) MetaImageIO
PNG † PNGImageIO
Raw ‡ RawImageIO
Siemens Vision SiemensVisionImageIO
Stimulate (spr/sdt) StimulateImageIO
TIFF TIFFImageIO
VTK Structured Points VTKImageIO

† BMP, PNG and JPEG are not very good formats for 3D medical images. They only support 2D images and a limited set of pixel types such as unsigned char, and unsigned short. The great advantage of BMP, PNG and JPEG is that you can view them with almost any image viewer. It is possible to read/write 3D datasets as collections of 2D slices each one in an independent BMP, PNG or JPEG file by using the ImageSerierReader and ImageSeriesWriter.

‡ It is higly recommended not using this format. RAW is not a format, it is insufficient, inconsistent and simply dangerous. A RAW file without a header is useless, and once you add a header, it is not RAW anymore.

What if my file format is not supported by ITK?

If ITK doesn't have a specific file format reader at this point, you may try converting this specific file format image to a format like PNG, for which ITK has readers.

A good set of tools for performing such conversions is available in ImageMagick. It can be downloaded it for free from: http://www.imagemagick.org/

You can also take advantage of the VTK readers/importers. All you need is then use the VTKImageToImage adaptor in order to convert the vtkImageData into an itk::Image.

Supported VTK file formats can be found here: What image file formats can VTK read and write? and What 3D file formats can VTK import and export

How do I read a volume from a DICOM series?

The following are alternative options for reading DICOM series. The first one in the list is the recommended option. The others are provided in case of desperation.

  1. Use the itk::ImageSeriesReader<> in combination with the DicomSeriesFileNames<>. For a full example on how to do this, please look at the source code under Insight/Code/Examples/IO/DicomSeriesReadImageWrite.cxx.
  2. Write a MetaImageHeader
    This is a small text file holding information about the image: spacing, dimensions, pixelt type... This header can hold the list of dicom files you want to read. The only restriction is that the files must be uncompressed.
    The easy way to create a MetaImage header is to use the application: MetaImageImporter that is available in: InsightApplications/MetaImageImporter. you can also take an existing metaimage reader and modify it in order to fit your needs. Please find attached one file that you can edit it with your favorite text editor.
  3. Use MRIConvert
    Jolinda Smith from the Lewis Center for Neuroimaging at the University of Oregon has developed a nice application that allows you to load DICOM series and export them in MetaImage and Analyze format (among others).
    She graciously has made this application publicly available at: http://lcni.uoregon.edu/~jolinda/MRIConvert There is a fresh version updated in april 14th.
  4. Jeff Brubaker and Stephen R. Aylward, at the UNC
    CADDLab developed a DICOM query/move application called "MIND" (whit the motto: "MIND is not DICOM"). This application loads DICOM files over the network and export them in MetaImage format. This application is open source and it is available at: http://www.jeffro.net/mind/ and http://caddlab.rad.unc.edu/software/MIND/

How do I write a volume as DICOM series?

Use ITK in combination with gdcm

http://gdcm.sourceforge.net/

GDCM is an open source package developed by the Creatis team at INSA-Lyon. It is distributed under a license similar to ITK.

http://gdcm.sourceforge.net/Copyright.html

GCDM uses CMake in order to configure its build process, so you will find a familiar setup. Once you download, configure and buid GDCM, you can reconfigure ITK by running CMake in your ITK build, going into the Advanced options and enabling USE_GDCM.

For a code example on how to use GDCM for reading and writing DICOM series, please refer to the source code in

Insight/Examples/IO/DicomSeriesReadImageWrite2.cxx

UPDATE: As of ITK 2.4 this option: USE_GDCM has disapear since GDCM is now the default toolkit for reading DICOM image. See also Proposals:Make_GDCM_the_default_DICOM.

You can always use the latest and greatest of GDCM, simply use an installed version of GDCM and link ITK to it using ITK_USE_SYSTEM_GDCM

Which interpreted languages are supported by ITK?

Currently ITK supports the following language bindings:

  • Python
  • Java

How do I cite the use of ITK in a publication?

The Insight software may be cited by referencing the paper, the books, and/or the web site.

A) The paper:

T.S. Yoo, M. J. Ackerman, W. E. Lorensen, W. Schroeder, V. Chalana, S. Aylward, D. Metaxes, R. Whitaker. Engineering and Algorithm Design for an Image Processing API: A Technical Report on ITK - The Insight Toolkit. In Proc. of Medicine Meets Virtual Reality, J. Westwood, ed., IOS Press Amsterdam pp 586-592 (2002).

B) The books:

"Insight into Images"
 edited by Terry Yoo
 published by A.K. Peters 2004
 ISBN: 1-56881-217-5
"The ITK Software Guide"
 Second Edition
 Ibanez, Schroeder, Ng, Cates.
 published by Kitware Inc.
 2005
 ISBN: 1-930934-15-7
"The ITK Software Guide"
 First Edition
 Ibanez, Schroeder, Ng, Cates.
 published by Kitware Inc.
 2003
 ISBN: 1-930934-10-6
"Mastering CMake,
 A Cross-Platform Build System"
 K. Martin and B. Hoffman
 published by Kitware Inc.
 ISBN:  1-930934-09-2

BiBtex citations


 @Manual{ITKSoftwareGuide,
   Title          = {The {ITK} {S}oftware {G}uide},
   Author         = {Ibanez, L. and Schroeder, W. and Ng, L. and Cates, J.},
   Organization   = "Kitware, Inc. ISBN 1-930934-10-6",
   Address        = {http://www.itk.org/ItkSoftwareGuide.pdf},
   Edition        = {First},
   year           = {2003}
   }


 @Manual{ITKSoftwareGuideSecondEdition,
   Title          = {The {ITK} {S}oftware {G}uide},
   Author         = {Ibanez, L. and Schroeder, W. and Ng, L. and Cates, J.},
   Organization   = "Kitware, Inc. ISBN 1-930934-15-7",
   Address        = {http://www.itk.org/ItkSoftwareGuide.pdf},
   Edition        = {Second},
   year           = {2005}
   }


C) The Web sites:

"The Insight Segmentation and Registration Toolkit"
 www.itk.org
"CMake: Cross Platform Make"
 www.cmake.org

If you want to include ITK in an acknowledgment section, a phrase similar to the following may be used:

"This work benefited from the use of the Insight Segmentation
 and Registration Toolkit (ITK), an open source software
 developed as an initiative of the U.S. National Library
 of Medicine and available at www.itk.org."

and

"The multi-platform configuration tool CMake was used for
 configuring ITK and facilitating its use from our project.
 CMake was partially funded by the U.S. National Library of
 Medicine as part of the Insight Toolkit project. CMake is an 
 open source system and it is freely available at www.cmake.org."

What does "Could not create IO object for file" mean?

When trying to read or write a file using the ImageFileReader or the ImageFileWriter I got an exception with the following message:

itk::ImageFileReaderException (00F7F494)
Location: "Unknown"
File: C:\ITK\InsightToolkit-1.6.0\Code\IO\itkImageFileReader.hxx
Line: 101
Description: Could not create IO object for file c:\t1.mnc

This exception is thrown when ITK does not recognize the fileformat that you are trying to read or write. When reading, ITK recognize file formats by asking a set of internal readers to attempt to read your file. If none of the registered readers accept your file, then the exception above is thrown. When writing, ITK uses the extension of the filename in order to chose the fileformat to be used. You must make sure that you use one of the filename extensions recognized by ITK. Please look at FAQ entry 1.7 for a full list of those extensions and associated fileformats.

Additional details on the ITK Input/Output architecture are available in the ITK Software Guide: http://www.itk.org/ItkSoftwareGuide.pdf.

Is ITK FDA-Approved?

Given the fact that ITK is a software toolkit, it cannot be the subject of FDA approval as a medical device. We have discussed this topic in several occasions and received advice from FDA representatives, that can be summarized as follow:


 ITK is to be considered as an off-the-shelf (OTS) product that
 is used for supporting a higher level medical application/product.
 The developer of such application/product will be responsible for
 performing the validation processes described in FDA published
 guidelines for the development of software-related medical devices.

For mode details see the page FDA Guidelines for Software Developement

Language bindings

What does "Error opening hint file NOTFOUND" mean?

When you enable "USE_VTK" in the CMake configuration of ITK, and VTK was built with wrapping, CMake looks for a "hints" file.

The "hints" file is on the VTK source tree under: VTK/Wrapping/hints

Please switch CMake to "advanced", look for the VTK_WRAP_HINTS variable and set it to the full path to the "hints" file including the "hints" filename itself.

here is how it looks in the CMakeCache.txt of a typical ITK installation:

//Where can the hints file be found
VTK_WRAP_HINTS:FILEPATH=/home/johndoe/src/VTK/Wrapping/hints

How do I use ITK with WrapITK?

Using the Insight Toolkit

How do I combine ITK and VTK in my application?

A full tutorial on how to combine ITK and VTK is available at

"Getting Started with ITK and VTK" http://www.itk.org/CourseWare/Training/GettingStarted-II.pdf

You will need the auxiliary classes available at

 ITKApps

For example, for converting ITK images into VTK images and back, you will find useful the files from the ITKVTKGlue module:

     itkImageToVTKImageFilter.h
     itkImageToVTKImageFilter.hxx
     itkVTKImageToImageFilter.h
     itkVTKImageToImageFilter.hxx

How do I configure Emacs for ITK coding style?

You can add the following codes into your .emacs file

;;;;;;;;;;;;;;
(c-add-style "itk"
            '("stroustrup" 
              (c-basic-offset . 2)
              (c-offsets-alist
                (c . c-lineup-dont-change)
                (innamespace . 0)
                (inline-open . 0) 
                (substatement-open . +)
                (statement-block-intro . 0) ) ) )
(add-hook 'c++-mode-hook (function (lambda ()
 (c-set-style "itk")(turn-on-auto-fill))))
(add-to-list 'auto-mode-alist '("\\.txx\\'" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
;;;;;;;;;;;

How do I configure VIM for ITK coding style?

set tabstop=2 " Tabs are two characters
set shiftwidth=2 " Indents are two charactes too
set expandtab " Do not use tabs
set matchpairs+=<:> " To mach arguments of templates
set cinoptions={1s,:0,l1,g0,c0,(0,(s,m1 " ITK/VTK style indenting

You can also use CMake indentation and syntax file which are available on www.vim.org.

This was contributed by Andy Cedilnik @kitware.com

If you'd like to enable c++ style syntax highlight for *.txx files, put the following lines in your .vimrc file:

syntax on
au BufNewFile,BufRead *.txx set filetype=cpp

Platform-specific questions

How do I avoid multiple prompts to reload all projects in Microsoft Visual Studio?

When the CMake source changes, you may see multiple prompts to reload many projects.

DO NOT USE "Rebuild All" or "Batch Build". Use the following recommended procedure.

There is an ALL_BUILD target available in the MSVC++ workspace. The best way to build ITK is to set ALL_BUILD as the active project, then select the active configuration you want (DEBUG, etc).

This can also be done from the command line like this: msdev ITK.dsw /MAKE "ALL_BUILD - Debug" /REBUILD

How do I fix Visual Studio 7 (2002) Compiler Issues?

The Visual Studio 7.0 compiler is more similar to the version 6 compiler than the version 7.1 compiler from the C++ conformance perspective. While it does not crash as frequently as version 6, there are some code patterns that still cause an INTERNAL COMPILER ERROR. Here is one example:

// Define a class template that has a data member of the template type.
template <class T> struct A { T v; };

// Define a primary template with no members.
template <class T> struct B {};

// Define a specialization that defines a type.
// This line is not actually necessary to cause the ICE but will be present when this problem is encountered in practice.
//template <> struct B<int> { typedef int Type; };

template <class T> struct C
{
  // Lookup the "Type" member of B<T>.  In practice this will reference a specialization.
  typedef typename B<T>::Type Type;

  // Use the result of the lookup to instantiate A<> and its data member.
  typedef typename A<Type>::A AType;
};

This will cause an ICE in msc1.cpp, line 2844. The work-around is to define the "Type" member in the primary template of B even though it will not be used:

template <class T> struct A { T v; };
template <class T> struct B { typedef T Type; };
template <class T> struct C
{
  typedef typename B<T>::Type Type;
  typedef typename A<Type>::A AType;
};

How do I fix prolems with MipsPro Compilers (7.3.3.1m and 7.4.2m) on IRIX?

There have been reports of problems building ITK on IRIX platform. Here are the compiler flags that are used to build ITK and submit nightly dashboard results. SGI Flags for both 7.3.3.1m and 7.4.2m compilers that are working for the kraepelin.uiowa nightly builds.

DEBUG BUILD: //No help, variable specified on the command line. CMAKE_CXX_FLAGS:STRING= -n32 -g -DUDEBUG -G0 -multigot -no_auto_include -xansi -LANG:std -LANG:ansi-for-init-scope=ON -woff 15,84,1110,1209,1424,1468,3102,3210,3439

//No help, variable specified on the command line. CMAKE_C_FLAGS:STRING= -n32 -g -DUDEBUG -G0 -multigot -xansi -woff 15,84,1110,1209,1424,1468,3102,3210,3439

OPTIMIZED BUILD: CMAKE_CXX_FLAGS:STRING= -n32 -O3 -DNDEBUG -G0 -multigot -no_auto_include -xansi -LANG:std -LANG:ansi-for-init-scope=ON -woff 15,84,1110,1209,1424,1468,3102,3210,3439

//No help, variable specified on the command line. CMAKE_C_FLAGS:STRING= -n32 -O3 -DNDEBUG -G0 -multigot -xansi -woff 15,84,1110,1209,1424,1468,3102,3210,3439

Contribute

How do I make code contributions to ITK?

ITKContribute

Testing

Is ITK tested regularly?

ITK is tested throughout the day on machines distributed around the world. You can view the results at:

http://www.itk.org/Testing/Dashboard/MostRecentResults-Nightly/Dashboard.html

or

http://www.cdash.org/CDash/index.php?project=Insight


ITK uses Dart and CDash to perform builds, run tests and generate dashboards. You can find more information about Dart at http://www.itk.org/Dart/. You can find more information about CDash at http://www.cdash.org.

What is the testing schedule?

Dart opens a daily dashboard at 9:00PM Eastern Daylight Time and keeps that dashbooard open for 24 hours. Build/Test results submitted as "nightlies" will appear on the currently opened dashboard. Each test site can select a convenient time to run tests.

Fresh dashboards are generated every hour, on the hour. They can also be generated on demand using the Rollup button on the dashboard. This button should be used sparingly since dashboard rollups can be time consuming.

In addition to nightly testing, several sites run Continuous build/tests. These sites monitor cvs repository activity and begin a build/test sequence if there are updates to the repository. If a compile error is detected, the Dashboard server sends email to the "offending" party.

What kind of testing is performed?

ITK has three types of tests:

  1. Unit Tests. Also called white box tests. These tests reside in the Testing/Code/XXX directories. There are meant to exercise a class's methods and verify that the code compiles, links and produces expected results. These tests do not need to produce results that are useful to a user. If a test returns a 0 status, it passes. A test fails if it returns a non-zero status.
  2. Blackbox Tests. These tests are automatically (or semi-automatically) generated. For example, each Code directory has a test called itkXXXHeaderTest. This test is automatically created and has a "#include" for each file in the directory.
  3. Regression Tests. These tests generate results and compare them with a known result. The purpose of regression testing is to detect changes in the output of the system.

How Do I Add a Test?

What is a continuous build and how can I contribute one?

Continuous builds run throughout the day and report their output in the Continuous Builds portion of the dashboard. The most recent build is at the top of the list. The builds run periodically and check the status of the repository. If a file is added or changed since the last build, the working repository of the continuous build is updated, the code compiled and tests executed. Optional e-mail norifications can be sent if there are errors, warmings or test failures.

You can set up a continuous build. This entails writing some small shell scripts and setting up a scheduler (Scheduler for Windows, cron for Linux/Unix). You will also need to install tcl, checkout Dart and configure your build for testing.

For Windows 2000, here are three batch files that can be modified for your own environment.

AllowInsightContinuous.bat
BuildInsightContinuous.bat
PreventInsightContinuous.bat

The batch files use a lock to prevent/allow the continuous

rem ************* AllowInsightContinuous.bat
rem Allow the Continuous to run
rem
c:
cd c:\lorensen\InsightContinuous\Insight-VC6
if EXIST continuous.lock (
  del continuous.lock
)
cd ..
rem ************* BuildInsightContinuous.bat
rem DO a C++ Build Continuously
rem
c:
rem Setup proxy it behind a firewall
set HTTP_PROXY=webcache
set HTTP_PROXY_PORT=8080
rem
rem Setup the path
rem
set PATH=c:/lorensen/InsightContinuous/Insight-VC6/bin/Release;%PATH%
rem
rem Tell cvs where .cvspass resides
set HOME=c:/lorensen
cd c:\lorensen\InsightContinuous\Insight-VC6
if EXIST continuous.lock (
  exit /B
) else (
  date /T > continuous.lock
  time /T >> continuous.lock
  cd c:\lorensen\InsightContinuous\Insight-VC6
 tclsh83 c:/lorensen/Dart/Source/Client/DashboardManager.tcl DartConfiguration.tcl Continuous Start Update Configure Build Test Submit
 cd c:\lorensen\InsightContinuous\Insight-VC6
 del continuous.lock
 cd ..
)
rem ***************** PreventInsightContinuous.bat
rem Prevent the Continuous
rem
c:
cd c:\lorensen\InsightContinuous\Insight-VC6
if EXIST continuous.lock (
  exit /B
) else (
  echo "Prevent continuous for nightly" > continuous.lock
)
cd ..

Now you need to establish a schedule for the three batch jobs. Use the "Scheduled Tasks" on the "Control Panel" to access the Schedule Task Wizard. The following schedule runs the continuous every 10 minutes from 6:05AM until 12:00AM. The Allow and Prevent scripts turn the build ON/OFF at the appropriate time. Schedule each batch file as follows:

AllowInsightContinuous.bat - Daily, Start 6:00AM
BuildInsightContinuous.bat - Daily, Start 6:05AM, Advanced: Repeat Task every 10 minutes, duration 17 hours and 55 minutes
PreventContinuous.bat - Daily, Start 12:00AM


Working with Image Data

How do I iterate through all the pixels in an image?

This requires the use of image iterators, which is explained in detail in the SoftwareGuide in Chapter 11, pdf-page 481.

Examples are available in `Insight/Examples/Iterators`. You probably want to use the ImageSliceIterator.

(Luis Ibanez, 7-Jun-2004)

What are Hounsfield Units?

Hounsfield units were defined by Sir Godfrey N. Hounsfield, on of the pioneers of Computer Tomography for clinical applications.

The units represent the linear attenuation of X-Rays for a particular material.

The units scale is defined in such a way that level for Water is 0 and the level for Air is -1000.

The attenuation of any other material is mapped linearly into this range.

A table of Hounsfield units for common human tissues is avalable in the following link ITK Hounsfield Units

What are MRI T1 / T2 Units?

MRI images measure two types of relaxation times.

The units are millisecons and the two relaxation concepts relate to how long it takes for the molecules in the tissue to realign themselves with a magentic field after being perturbed.

Details on the MRI units are available in the Wikipedia:

Relaxation (NMR)

DICOM: Bits Allocated, Bits Stored and High Bit

A question that is often asked on insight-users is : I am trying to read/write a DICOM image, but some of the DICOM fields have changed after I write it back on disk.

Here is what you have on disk:

        Bits Allocated = 16
        Bits Stored    = 12
        High Bit       = 11

                          |<------------------ pixel ----------------->|
            ______________ ______________ ______________ ______________
           |XXXXXXXXXXXXXX|              |              |              |
           |______________|______________|______________|______________|
            15          12 11           8 7            4 3            0

Here is what you generally get after writing by GDCM:

        Bits Allocated = 16
        Bits Stored    = 16
        High Bit       = 15

            |<------------------------- pixel ------------------------>|
            ______________ ______________ ______________ ______________
           |              |              |              |              |
           |______________|______________|______________|______________|
            15          12 11           8 7            4 3            0

Since DICOM V3, you cannot store any overlay in the unused bits of the Pixel Data (0x7fe0,0x0010), thus it imply that the unused bits are zeros. In ITK, there is no such thing as 12bits Pixel Type, thus when instanciating your reader you declare a 16bits Pixel Type. This buffer is then passed back to GDCM which sees an array of 16bits values and then simply used the simpliest way to store this buffer back on disk: Bits Stored = 16 and High Bit = 15. In case you have not made any change to your pixel buffer, implicitely the first 4 bits will be zero again. The only difference being that they are not as clearly declared as 12bits.

DICOM: Rescale Slope/Intercept

Another question that is often asked on insight-users is : I am trying to read/write a DICOM image, but the pixel data has changed (the scalar range has changed from input file).

This surely comes from the fact that you did not used the proper PixelType to instanciate your reader. You have to consider :

  • Bits Allocated
  • Bits Stored
  • Pixel Representation
  • Samples per Pixel

AND:

  • Rescale Intercept
  • Rescale Slope

For instance you can use the DicomImageReadPrintTags example in ITK/IO, or even better gdcminfo

$ DicomImageReadPrintTags image.dcm | grep "Slope\|Intercept\|Bits\|Pixel Rep"
(0028|0100) Bits Allocated = 16
(0028|0101) Bits Stored = 12
(0028|0103) Pixel Representation = 0
(0028|1052) Rescale Intercept = -1000
(0028|1053) Rescale Slope = 1

In this case when you look only at how the pixel are stored on disk: Bits Allocated, Bits Stored and Pixel Representation, you clearly see that they are stored as unsigned short. However looking now at how the pixel are mapped to real world value you need to apply an afine transform:

 RWV = slope * SP + intercept

In which case you'll get signed value. Therefore you will need a signed short pixel to display the pixel value.

One might ask, how can I be sure that signed short will be enough for loading the stored pixel value ? You have two clues: either look at pixel stored: 12bits, therefore you know that signed short will be enough. Or you can have a look sometimes at Smallest Image Pixel Value / Largest Image Pixel Value. It will tell you what are the min/max in your stored image:

$ DicomImageReadPrintTags image.dcm | grep "Image Pixel Value"
(0028|0106) Smallest Image Pixel Value = 0
(0028|0107) Largest Image Pixel Value = 4095

DICOM: Why did the header of my DICOM file change ?

A common that frequently arises on ITK mailing list after using itk::GDCMImageIO to read, update and write out a DICOM file is: why did my header file changed during the update mechanism ?

DICOM has a specific section on what is a 'DERIVED' image (PS 3.3-2008, C.7.6.1.1.2 Image Type)

If the pixel data of the derived Image is different from the pixel
data of the source images and this difference is expected to affect
professional interpretation of the image, the Derived Image shall have
a UID different than all the source images."

Further, in the definition of Derivation Description there is a note which says (PS 3.3-2008, C.7.6.1.1.3 Derivation Description)

Examples of Derived Images which would normally be expected to affect
professional interpretation and would thus have a new UID include:
1. Examples of Derived Images that would normally be expected to affect professional
interpretation and would thus have a new UID include:
a. images resulting from image processing of another image (e.g. unsharp masking),
b. a multiplanar reformatted CT image,
c. a DSA image derived by subtracting pixel values of one image from another.
d. an image that has been decompressed after having been compressed with a lossy
compression algorithm. To ensure that the user has the necessary information about the
lossy compression, the approximate compression ratio may be included in Derivation
Description (0008,2111).
An example of a Derived Image that would normally not be expected to affect professional
interpretation and thus would not require a new UID is an image that has been padded with
additional rows and columns for more display purposes.

At a minimum you should expect the minimal set of changes:

  • assign a new SOP Instance UID
  • reference the SOP Instance UID of the original in Source Image Sequence
  • set the Image Type value 1 to DERIVED rather than ORIGINAL

The identical SOP-Instance UID of two files mean that both files are representations of the same objects and thus have identical content. It is however allowed that both files uses different transfer syntax uid (ie. they have a different binary representation on disk) (implicit/explicit, little/big endian). When a DICOM file is sent to a PACS, it is up to the implementor to decide what to do in case of duplicate SOP Instance UID. In most case you should expect that the image is not resent, as standard garantee this is already the same object.


Warning: Adding Overlay is considered to 'affect professional interpretation' of the images. Thus new UIDs are required !

Data Display

What imaging software is available for displaying medical image files?

Here are some viewing options for the image fileformats supported in ITK:

1. Scalar images:

2. Color Images:

3. Vector Images:

  • ParaView (glyphs, streamlines, composites).

When I view the output of my program, all I see is a black image. What went wrong?

ITK is capable of reading and writing data in a variety of formats and bit depths. However many 'consumer' image programs only work with 8-bit data, so when you try to display a 16-bit data file the image will appear black. The solution is to use an image display program that correctly handles these types of files. A small selection is listed above.

ImageMagick is a particularly useful set of tools for image display, manipulation and conversion.

The `ImageViewer` program, part of InsightApplications, is capable of correctly loading and displaying all file types supported by ITK (including anisotropic images).

(Gavin Baker, 24-Jun-2004)

Registration

Can ITK be used for multi-modal registration? For example, CT-MRI, or MRI-fMRI?

ITK provides several method for performing Multi-Modality registration. These methods are described in detail in the SoftwareGuide Chapter 8, pdf-page 241 to 340. In particular you will find interesting Section 8.4 in pdf-page 255 where the Mutual Information metrics are described.

Examples on multimodality registration are available in `Insight/Examples/Registration`. A demo application using Mutual Information is available under `InsightApplications/LandmarkInitializedMutualInformationRegistration`.

It is strongly recommended that you read the chapter on image resampling (Section 6.9.4 of the pdf) before you get involved with image registration methods. That will save you a lot of misunderstandings that are common in new users.

You will also find useful the tutorial sessions, in particular the overview.

(Luis Ibanez, 7-June-2004)

Miscellaneous

How to copy an image

See itk::ImageDuplicator.



ITK: [Welcome | Site Map]