Defines safe input and output of itk::Images. More...
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#include "itkCastImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkImageIOBase.h"
#include "itkImageIOFactory.h"
#include "itkNiftiImageIO.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkNumericSeriesFileNames.h"
#include "itkOrientImageFilter.h"
#include "itkChangeInformationImageFilter.h"
#include "gdcm/src/gdcmFile.h"
#include "gdcm/src/gdcmUtil.h"
#include "cbicaUtilities.h"
#include "cbicaITKImageInfo.h"
#include "cbicaITKUtilities.h"
#include "DicomIOManager.h"
Go to the source code of this file.
Typedefs | |
using | ImageTypeFloat3D = itk::Image< float, 3 > |
using | MaskType = itk::Image< unsigned int, 3 > |
using | TImageType = ImageTypeFloat3D |
Functions | |
template<class TImageType = ImageTypeFloat3D> | |
itk::ImageSeriesReader< TImageType >::Pointer | GetDicomImageReader (const std::string &dirName) |
Returns the unique series IDs in the specified directory. More... | |
template<class TImageType = ImageTypeFloat3D> | |
TImageType::Pointer | GetImage (const std::string &fName, const std::string &supportedExtensions=".nii.gz,.nii", const std::string &delimitor=",") |
Get the itk::Image from input file name. More... | |
template<class TImageType = ImageTypeFloat3D> | |
itk::ImageFileReader< TImageType >::Pointer | GetImageReader (const std::string &fName, const std::string &supportedExtensions=".nii.gz,.nii,.dcm", const std::string &delimitor=",") |
Get the itk::ImageFileReader from input file name. More... | |
template<class TImageType > | |
TImageType::Pointer | GetImageWithOrientFix (const typename TImageType::Pointer inputImage) |
This is an inline function used to correct the orientation for correct visualization. More... | |
template<class TImageType = ImageTypeFloat3D> | |
TImageType::Pointer | ReadImage (const std::string &fName, const std::string &supportedExtensions=".nii.gz,.nii,.dcm", const std::string &delimitor=",") |
Get the itk::Image from input file name. More... | |
template<class TImageType > | |
TImageType::Pointer | ReadImageWithOrientFix (const std::string &fName, const std::string &supportedExtensions=".nii.gz,.nii", const std::string &delimitor=",") |
The reads the image according to the appropriate extension and outputs the result in ITK's RAI orientation for visualization. More... | |
template<typename ComputedImageType = ImageTypeFloat3D> | |
void | WriteDicomImage (const typename ComputedImageType::Pointer imageToWrite, const std::string &dirName) |
template<typename ComputedImageType = ImageTypeFloat3D> | |
void | WriteDicomImage (const typename itk::ImageSeriesReader< ComputedImageType >::Pointer inputImageReader, const typename ComputedImageType::Pointer imageToWrite, const std::string &dirName) |
Write the itk::Image as a DICOM to the specified directory. More... | |
template<typename ComputedImageType = ImageTypeFloat3D, typename ExpectedImageType = ComputedImageType> | |
void | WriteImage (typename ComputedImageType::Pointer imageToWrite, const std::string &fileName) |
Get the itk::Image from input dir name. More... | |
Defines safe input and output of itk::Images.
Read and Write itk::Image data in a safe manner. Header-only
https://www.cbica.upenn.edu/sbia/software/
softw are@ cbica .upe nn.ed u
Copyright (c) 2018 University of Pennsylvania. All rights reserved.
See COPYING file or https://www.cbica.upenn.edu/sbia/software/license.html
itk::ImageSeriesReader< TImageType >::Pointer cbica::GetDicomImageReader | ( | const std::string & | dirName | ) |
Returns the unique series IDs in the specified directory.
The check is only done on the DICOM tag provided, so if there are series with the same UID information (but are indeed different images), this function will not able to handle it.
dirName | The directory in question |
tagToCheck | The tag on the basis of which the test is done; defaults to "0x0020|0x00E" |
Usage:
typedef itk::Image< float, 3 > ExpectedImageType; std::string inputDirName = parser.getParameterValue("inputDirName"); auto inputImageReader = GetDicomImageReader< ExpectedImageType >(inputDirName); // reads *all* DICOM images auto inputImage = inputImageReader->GetOutput(); DoAwesomeStuffWithImage( inputImage );
dirName | This is the directory name of the DICOM image which needs to be loaded - if this is an image, the underlying path of the image is considered |
References cbica::GetDicomImageReader(), cbica::getFilenamePath(), cbica::GetUniqueElements(), cbica::isDir(), and cbica::normPath().
Referenced by cbica::GetDicomImageReader().
TImageType::Pointer cbica::GetImage | ( | const std::string & | fName, |
const std::string & | supportedExtensions = ".nii.gz,.nii" , |
||
const std::string & | delimitor = "," |
||
) |
Get the itk::Image from input file name.
Usage:
using ExpectedImageType = itk::Image< float, 3 >; std::string inputFileName = parser.getParameterValue("inputImage"); auto inputImage_1 = cbica::ReadImage< ExpectedImageType >(inputFileName); auto inputImage_2 = cbica::ReadImage< ExpectedImageType >(inputFileName, ".nii.gz,.img"); DoAwesomeStuffWithImage( inputImage );
fName | File name of the image |
supportedExtensions | Supported extensions, defaults to ".nii.gz,.nii" |
References cbica::GetImage().
Referenced by cbica::GetImage().
itk::ImageFileReader< TImageType >::Pointer cbica::GetImageReader | ( | const std::string & | fName, |
const std::string & | supportedExtensions = ".nii.gz,.nii,.dcm" , |
||
const std::string & | delimitor = "," |
||
) |
Get the itk::ImageFileReader from input file name.
This is useful for scenarios where reader meta information is needed for later writing step(s).
Usage:
typedef itk::Image< float, 3 > ExpectedImageType; std::string inputFileName = parser.getParameterValue("inputImage"); ExpectedImageType::Pointer inputImage_1 = GetImageReader< ExpectedImageType >(inputFileName)->GetOutput(); ExpectedImageType::Pointer inputImage_2 = GetImageReader< ExpectedImageType >(inputFileName, ".nii.gz,.img")->GetOutput(); DoAwesomeStuffWithImage( inputImage );
fName | name of the image |
supportedExtensions | Supported extensions, defaults to ".nii.gz,.nii" |
References cbica::filesInDirectory(), cbica::getFilenameExtension(), cbica::getFilenamePath(), cbica::GetImageReader(), cbica::normPath(), and cbica::stringSplit().
Referenced by cbica::GetImageReader().
|
inline |
This is an inline function used to correct the orientation for correct visualization.
inputImage | The input image |
References cbica::GetImageWithOrientFix().
Referenced by cbica::GetImageWithOrientFix().
TImageType::Pointer cbica::ReadImage | ( | const std::string & | fName, |
const std::string & | supportedExtensions = ".nii.gz,.nii,.dcm" , |
||
const std::string & | delimitor = "," |
||
) |
Get the itk::Image from input file name.
Usage:
typedef itk::Image< float, 3 > ExpectedImageType; std::string inputFileName = parser.getParameterValue("inputImage"); ExpectedImageType::Pointer inputImage_1 = ReadImage< ExpectedImageType >(inputFileName); ExpectedImageType::Pointer inputImage_2 = ReadImage< ExpectedImageType >(inputFileName, ".nii.gz,.img"); DoAwesomeStuffWithImage( inputImage );
fName | name of the image |
supportedExtensions | Supported extensions, defaults to ".nii.gz,.nii" |
References DicomIOManager< T >::GetITKImage(), DicomIOManager< T >::LoadDicom(), cbica::ReadImage(), and DicomIOManager< T >::SetDirectoryPath().
Referenced by cbica::ReadImage().
TImageType::Pointer cbica::ReadImageWithOrientFix | ( | const std::string & | fName, |
const std::string & | supportedExtensions = ".nii.gz,.nii" , |
||
const std::string & | delimitor = "," |
||
) |
The reads the image according to the appropriate extension and outputs the result in ITK's RAI orientation for visualization.
Usage:
using ExpectedImageType = itk::Image< float, 3 >; std::string inputFileName = parser.getParameterValue("inputImage"); auto inputImage_1 = ReadImageWithOrientFix< ExpectedImageType >(inputFileName); auto inputImage_2 = ReadImageWithOrientFix< ExpectedImageType >(inputFileName, ".nii.gz,.img"); DoAwesomeStuffWithImage( inputImage );
fName | File name of the image |
supportedExtensions | Supported extensions, defaults to ".nii.gz,.nii" |
References cbica::getFilenameExtension(), and cbica::ReadImageWithOrientFix().
Referenced by cbica::ReadImageWithOrientFix().
void cbica::WriteDicomImage | ( | const typename itk::ImageSeriesReader< ComputedImageType >::Pointer | inputImageReader, |
const typename ComputedImageType::Pointer | imageToWrite, | ||
const std::string & | dirName | ||
) |
Write the itk::Image as a DICOM to the specified directory.
Usage:
typedef itk::Image< float, 3 > ComputedImageType; typedef itk::Image< unsigned char, 3 > WrittenImageType; itk::ImageSeriesReader< ComputedImageType >::Pointer inputImageReader = GetDicomImageReader< ComputedImageType >(inputDirName); ComputedImageType::Pointer imageToWrite = GetImageAfterProcessing( inputImageReader->GetOutput() ); WriteImage< ComputedImageType, WrittenImageType >(inputImageReader, imageToWrite, dirNameToWriteImage); // casts imageToWrite to WrittenImageType WriteImage< ComputedImageType >(inputImageReader, imageToWrite, dirNameToWriteImage); // writes imageToWrite as ComputedImageType // at this point, the image has already been written
inputImageReader | The image reader for DICOM - this is necessary to populate the DICOM dictionary properly |
imageToWrite | Pointer to processed image data which is to be written |
dirName | File containing the image |
References cbica::createDir(), and cbica::isDir().
void cbica::WriteImage | ( | typename ComputedImageType::Pointer | imageToWrite, |
const std::string & | fileName | ||
) |
Get the itk::Image from input dir name.
Usage:
typedef itk::Image< float, 3 > ExpectedImageType; std::string inputDirName = parser.getParameterValue("inputDirName"); ExpectedImageType::Pointer inputImage_1 = ReadDicomImage< ExpectedImageType >(inputFileName); // reads MRI and perfusion data by default tags "0008|0021,0020|0012" ExpectedImageType::Pointer inputImage_2 = ReadDicomImage< ExpectedImageType >(inputDirName, "0008|0021")->GetOutput(); // only reads images with tag "0008|0021" DoAwesomeStuffWithImage( inputImage );
fName | name of the image |
supportedExtensions | Supported extensions |
Usage:
typedef itk::Image< float, 3 > ExpectedImageType; std::string inputDirName = parser.getParameterValue("inputDirName"); ExpectedImageType::Pointer inputImage_1 = ReadDicomImage< ExpectedImageType >(inputFileName); // reads MRI and perfusion data by default tags "0008|0021,0020|0012" ExpectedImageType::Pointer inputImage_2 = ReadDicomImage< ExpectedImageType >(inputDirName, "0008|0021")->GetOutput(); // only reads images with tag "0008|0021" DoAwesomeStuffWithImage( inputImage );
This function calls ReadDicomImage<> internally
fName | name of the image |
supportedExtensions | Supported extensions |
Usage:
typedef itk::Image< float, 3 > ComputedImageType; typedef itk::Image< unsigned char, 3 > WrittenImageType; ComputedImageType::Pointer imageToWrite = ComputedImageType::New(); imageToWrite = GetImageSomehow(); WriteImage< ComputedImageType >(imageToWrite, fileNameToWriteImage); // casts imageToWrite to WrittenImageType WriteImage< ComputedImageType, WrittenImageType >(imageToWrite, fileNameToWriteImage); // writes imageToWrite as ComputedImageType // at this point, the image has already been written
inputImage | Pointer to processed image data which is to be written |
fileName | File containing the image |
References cbica::getFilenameExtension(), and cbica::WriteImage().
Referenced by cbica::WriteImage().