Difference between revisions of "ITK/File Formats"

From KitwarePublic
< ITK
Jump to navigationJump to search
(64-bit pixel type support on all platforms provided by http://review.source.kitware.com/#/c/21513/)
 
(16 intermediate revisions by 13 users not shown)
Line 1: Line 1:
ITK features a powerful plugin-based IO mechanism for reading and writing images, which is covered in detail in Chapter 7 (PDF page 219) of the [http://www.itk.org/ItkSoftwareGuide.pdf ITK Software Guide].
ITK features a powerful plugin-based IO mechanism for reading and writing images, which is covered briefly in [[Plugin IO mechanisms]] and in detail in Chapter 7 (PDF page 219) of the [http://www.itk.org/ItkSoftwareGuide.pdf ITK Software Guide]. The discussion in [[Plugin IO mechanisms]] also discusses how new file formats can be added existing compiled applications!


== File Formats and Pixel Types ==
== File Formats and Pixel Types ==
Line 7: Line 7:
The following table lists the built-in file format support against each data type:
The following table lists the built-in file format support against each data type:


* Analyze
* Analyze/NIFTI
  char
  char
  unsigned char
  unsigned char
Line 14: Line 14:
  int
  int
  unsigned int
  unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
  float
  float
  double
  double
Line 44: Line 46:
  short
  short
  unsigned short
  unsigned short
int
  unsigned int
  unsigned int
int
  float
  float
  double
  double
short
  surface
  surface
  polygon
  polygon
* IPL
* IPL
  ???
  short
* JPEG (2D only)
* JPEG (2D only)
  unsigned char
  unsigned char
Line 64: Line 65:
  int
  int
  unsigned int
  unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
  float
  float
  double
  double
Line 72: Line 75:
   - data stored in multiple files (e.g., a metaImage file could be a text file pointing to a series of
   - data stored in multiple files (e.g., a metaImage file could be a text file pointing to a series of
       2D images that are stacked to form the 3D metaImage).
       2D images that are stacked to form the 3D metaImage).
* Nrrd
Reference: http://www.itk.org/Wiki/MetaIO
  char
* Nrrd (.nhdr, .nrrd): raw or gzip compressed
  signed char
  unsigned char
  unsigned char
  short
  short
Line 79: Line 83:
  int
  int
  unsigned int
  unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
  float
  float
  double
  double
vector<>
Also supports reading and writing
  - all the pixel types in ImageIOBase, including DIFFUSIONTENSOR3D
  - MetaData dictionary, via mapping to key/value pairs
  - data from multiple files, using MetaIO conventions
[[Getting Started with the NRRD Format]]
[http://teem.sourceforge.net/nrrd/format.html NRRD format definition]
*PNG (2D)
*PNG (2D)
  unsigned char
  unsigned char
Line 107: Line 122:
  unsigned int
  unsigned int
  int
  int
  unsigned long
  unsigned long long (on 64-bit platforms)
  long
  long long (on 64-bit platforms)
  RGB
  RGB


Line 139: Line 154:
The input frames need not have the names that the original
The input frames need not have the names that the original
ImageSeriesReadWrite expects.
ImageSeriesReadWrite expects.
=== Converting unsupported 2D images to an ITK supported format ===
[http://www.imagemagick.org ImageMagick] supports conversion between over 90 (typically 2D) image formats as well as some basic image processing.  Operates from the command line on PCs and on *nix machines.
{{ITK/Template/Footer}}

Latest revision as of 18:45, 13 November 2017

ITK features a powerful plugin-based IO mechanism for reading and writing images, which is covered briefly in Plugin IO mechanisms and in detail in Chapter 7 (PDF page 219) of the ITK Software Guide. The discussion in Plugin IO mechanisms also discusses how new file formats can be added existing compiled applications!

File Formats and Pixel Types

The itk::Image<> class can be templated over virtually any pixel type, however not all file formats support all data types for reading and writing. In some cases, it may be necessary to add an itk::CastImageFilter<> to convert the output to a pixel format appropriate for the target file. It is important not to truncate the data by converting to a smaller type (ie. short -> char). In this case, the itk::RescaleIntensityImageFilter<> can be used before casting.

The following table lists the built-in file format support against each data type:

  • Analyze/NIFTI
char
unsigned char
short
unsigned short
int
unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
float
double
RGB<unsigned char>
  • BMP (2D only)
unsigned char
RGB<unsigned char>
  • DICOM
float
char
unsigned char
short
unsigned short
RGB<char>
RGB<short>
  • GDCM
unsigned char
char
unsigned short
short
unsigned int
int
double
  • GE
???
  • GIPL
binary
char
unsigned char
short
unsigned short
int
unsigned int
float
double
surface
polygon
  • IPL
short
  • JPEG (2D only)
unsigned char
  • MetaImage (mhd): raw, compressed
char
unsigned char
short
unsigned short
long
ulong
int
unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
float
double
vector<>
Also supports reading and writing 
  - itk's SpatialObjects (i.e., scenes containing ellipses, images, vessels, dti fiber tracks, etc)
  - Patient Meta Data (orientation, scan date, comments, modality, etc. - user extensible)
  - data stored in multiple files (e.g., a metaImage file could be a text file pointing to a series of
     2D images that are stacked to form the 3D metaImage).
Reference: http://www.itk.org/Wiki/MetaIO
  • Nrrd (.nhdr, .nrrd): raw or gzip compressed
signed char
unsigned char
short
unsigned short
int
unsigned int
long long (on 64-bit platforms)
unsigned long long (on 64-bit platforms)
float
double
vector<>
Also supports reading and writing
 - all the pixel types in ImageIOBase, including DIFFUSIONTENSOR3D
 - MetaData dictionary, via mapping to key/value pairs
 - data from multiple files, using MetaIO conventions

Getting Started with the NRRD Format

NRRD format definition

  • PNG (2D)
unsigned char
unsigned short
RGB
RGBA
  • SiemensVision
???
  • Stimulate
char
short
int
float
double
  • TIFF (2D only)
unsigned char
unsigned short
RGB
  • VTK
float
double
unsigned char
char
unsigned short
short
unsigned int
int
unsigned long long (on 64-bit platforms)
long long (on 64-bit platforms)
RGB

Importing other file format

Movies as 3D images

From the Insight-User Amadeus:

I work exclusively in Linux and one can use mplayer - the mother of all multimedia tools - to dump each frame in a movie clip. MPlayer understands just about any format under the sun and can use just about any codec as well. E.g. to dump each frame in an avi clip to a separate png image

mplayer -vo png movie.avi

To see to what other formats one can output the frames to,

mplayer -vo help

Then, the frames dumped by mplayer can be put together into a volume using ImageSeriesReadWrite in InsightToolkit-2.0.0/Examples/IO/.

Of course, in Linux and other unixes the shell understands wildcards, so with minor changes, it ImageSeriesReadWrite can be modified to work like this:

ImageSeriesReadWrite frame*.png output.mha # or e.g. output.mhd

The input frames need not have the names that the original ImageSeriesReadWrite expects.

Converting unsupported 2D images to an ITK supported format

ImageMagick supports conversion between over 90 (typically 2D) image formats as well as some basic image processing. Operates from the command line on PCs and on *nix machines.



ITK: [Welcome | Site Map]