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 ITK Software Guide. Plugin IO mechanisms also discusses how new file formats can be added to ITK, even to 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:
char unsigned char short unsigned short int unsigned int float double RGB<unsigned char>
- BMP (2D only)
unsigned char RGB<unsigned char>
float char unsigned char short unsigned short RGB<char> RGB<short>
unsigned char char unsigned short short unsigned int int double
binary char unsigned char short unsigned short unsigned int int float double short surface polygon
- JPEG (2D only)
- MetaImage (mhd): raw, compressed
char unsigned char short unsigned short long ulong int unsigned int 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).
char unsigned char short unsigned short int unsigned int float double
- PNG (2D)
unsigned char unsigned short RGB RGBA
char short int float double
- TIFF (2D only)
unsigned char unsigned short RGB
float double unsigned char char unsigned short short unsigned int int unsigned long long 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.