CBICA Toolkit  1.0.0
cbicaITKUtilities.h File Reference

Some basic utility functions. More...

#include <algorithm>
#include <functional>
#include <cmath>
#include "itkImage.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkImageRegionIterator.h"
#include "itkHistogramMatchingImageFilter.h"
#include "itkAdaptiveHistogramEqualizationImageFilter.h"
#include "itkConnectedThresholdImageFilter.h"
#include "itkOrientImageFilter.h"
#include "itkResampleImageFilter.h"
#include "itkIdentityTransform.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkBSplineInterpolateImageFunction.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkTestingComparisonImageFilter.h"
#include "itkStripTsImageFilter.h"
#include "itkMaskImageFilter.h"
#include "cbicaUtilities.h"
#include "cbicaITKImageInfo.h"
#include "gdcmMD5.h"
#include "gdcmReader.h"
#include "DicomIOManager.h"
Include dependency graph for cbicaITKUtilities.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using ImageTypeFloat3D = itk::Image< float, 3 >
 

Enumerations

enum  DeformRegType { Demons, DiffeomorphicDemons, SymmetricForcesDemons, FastSymmetricForcesDemons }
 
enum  InterpolatorType { Linear, NearestNeighbor, BSpline }
 

Functions

template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer ChangeImageValues (const typename TImageType::Pointer inputImage, const std::string &oldValues, const std::string &newValues)
 Create an empty (optionally pass a value) ITK image based on an input image with same properties. More...
 
template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer CreateImage (const typename TImageType::Pointer inputImage, const typename TImageType::PixelType value=0)
 Create an empty (optionally pass a value) ITK image based on an input image with same properties. More...
 
template<class TImageType = ImageTypeFloat3D>
std::vector< std::vector< typename TImageType::IndexType > > CreateMaskIndeces (const std::vector< std::vector< typename TImageType::Pointer > > &inputModalitiesAndImages)
 Calculate and preserve the mask indeces. More...
 
template<typename TImageType = ImageTypeFloat3D>
std::vector< typename TImageType::PixelType > ExtractPixelValuesFromIndeces (const typename TImageType::Pointer inputImage, const std::vector< typename TImageType::IndexType > &indeces)
 Wrap of GetPixelValues.
 
template<typename TImageType = ImageTypeFloat3D>
TImageType::Pointer GetAdaptiveHistogramEqualizedImage (const typename TImageType::Pointer inputImage, const typename TImageType::Pointer referenceImage, const float alpha=0.3, const float beta=0.3, const float radius=1, const int numberOfHistogramLevels=100)
 Get the indeces of the image which are not zero. More...
 
template<class TImageType = ImageTypeFloat3D>
float GetDistanceBetweenIndeces (const typename TImageType::IndexType point1, const typename TImageType::IndexType point2)
 Get the distance between 2 indeces of an itk::Image.
 
float GetDistanceBetweenIndeces (const float *point1, const float *point2)
 Get the distance between 2 itk::P of an itk::Image.
 
template<typename TImageType = ImageTypeFloat3D>
itk::Vector< float, TImageType::ImageDimension > GetDistances (const typename TImageType::Pointer inputImage)
 Get distances in world coordinates across axes for an image. More...
 
template<typename TImageType = ImageTypeFloat3D>
TImageType::Pointer GetHistogramMatchedImage (const typename TImageType::Pointer inputImage, const typename TImageType::Pointer referenceImage, const int numberOfMatchPoints=40, const int numberOfHistogramLevels=100)
 Get the indeces of the image which are not zero. More...
 
template<class TImageType = ImageTypeFloat3D>
std::pair< std::string, typename TImageType::Pointer > GetImageOrientation (const typename TImageType::Pointer inputImage)
 Perform the deformable registration. More...
 
template<typename TImageType = ImageTypeFloat3D>
std::vector< typename TImageType::IndexType > GetIndexFromNonZeroPixels (const typename TImageType::Pointer inputImage, const std::string valuesToExclude="0")
 Get MD5 sum of a supplied file. More...
 
template<class TImageType = ImageTypeFloat3D>
std::pair< float, typename TImageType::IndexType > GetMaxDistanceInLabelMap (const typename TImageType::Pointer inputLabelMap, const typename TImageType::IndexType indexForComputation, bool realCoordinateInput=false, bool realCoordinateOutput=false)
 Get the maximum distance and corresponding coordinate from a seed point in a label map. More...
 
template<class TImageType = ImageTypeFloat3D>
std::vector< typename TImageType::IndexType > GetNonZeroIndeces (typename TImageType::Pointer inputImage)
 Get Non-zero indeces of image.
 
template<typename TImageType = ImageTypeFloat3D>
std::vector< typename TImageType::PixelType > GetPixelValuesFromIndeces (const typename TImageType::Pointer inputImage, const std::vector< typename TImageType::IndexType > &indeces)
 Get Pixel Values of specified indeces of input Image. More...
 
template<class TImageType = ImageTypeFloat3D>
bool GetResultOfImageComparasion (const typename TImageType::Pointer referenceImage, const typename TImageType::Pointer checkImage, const typename TImageType::PixelType differenceThreshold=0, const unsigned int toleranceRadius=0, const unsigned long long numberOfPixelsTolerance=10, const typename TImageType::PixelType averageIntensityDifference=0)
 Get result of Image comparison between 2 images. More...
 
template<class TImageType = ImageTypeFloat3D, class TAtlasImageType = TImageType, class TAtlasLabelType = TImageType>
TImageType::Pointer GetSkullStrippedImage (const typename TImageType::Pointer inputImage, const typename TAtlasImageType::Pointer atlasImage, const typename TAtlasLabelType::Pointer atlasLabelImage)
 Get skull stripped image. More...
 
template<class TImageType = ImageTypeFloat3D>
std::vector< typename TImageType::PixelType > GetUniqueValuesInImage (typename TImageType::Pointer inputImage, bool sortResult=true)
 Get the unique values in an image. More...
 
template<typename TImageType >
bool ImageSanityCheck (const typename TImageType::Pointer image1, const typename TImageType::Pointer image2)
 Check properties of 2 images to see if they are defined in the same space.
 
bool ImageSanityCheck (const std::string &image1, const std::string &image2)
 Check properties of 2 images to see if they are defined in the same space. More...
 
template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer ResampleImage (const typename TImageType::Pointer inputImage, const itk::Vector< double, TImageType::ImageDimension > &outputSpacing, const std::string interpolator="Linear")
 Resample an image to an isotropic resolution using the specified output spacing vector. More...
 
template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer ResampleImage (const typename TImageType::Pointer inputImage, const typename TImageType::SpacingType outputSpacing, typename TImageType::SizeType outputSize, const std::string interpolator="Linear")
 Resample an image to an isotropic resolution using the specified output spacing vector. More...
 
template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer ResampleImage (const typename TImageType::Pointer inputImage, const float outputSpacing=1.0, const std::string interpolator="Linear")
 Resample an image to an isotropic resolution using the specified output spacing. More...
 
template<class TImageType = ImageTypeFloat3D>
TImageType::Pointer ResizeImage (const typename TImageType::Pointer inputImage, const size_t resizeFactor, const std::string &interpolator="Linear")
 Resize an input image by a factor (expressed as a percentage) More...
 

Detailed Description

Some basic utility functions.

Dependecies: ITK (module_review, module_skullstrip enabled), OpenMP

https://www.cbica.upenn.edu/sbia/software/
softw.nosp@m.are@.nosp@m.cbica.nosp@m..upe.nosp@m.nn.ed.nosp@m.u

Copyright (c) 2015 University of Pennsylvania. All rights reserved.
See COPYING file or https://www.cbica.upenn.edu/sbia/software/license.html

Function Documentation

◆ ChangeImageValues()

TImageType::Pointer cbica::ChangeImageValues ( const typename TImageType::Pointer  inputImage,
const std::string &  oldValues,
const std::string &  newValues 
)

Create an empty (optionally pass a value) ITK image based on an input image with same properties.

Parameters
inputImageThe image to base the output on
oldValuesValues separated by 'x'
newValuesValues separated by 'x'

References cbica::ChangeImageValues(), and cbica::stringSplit().

Referenced by cbica::ChangeImageValues().

◆ CreateImage()

TImageType::Pointer cbica::CreateImage ( const typename TImageType::Pointer  inputImage,
const typename TImageType::PixelType  value = 0 
)

Create an empty (optionally pass a value) ITK image based on an input image with same properties.

Parameters
inputImageThe image to base the output on
valueThe value to populate the new image with; defaults to '0'

References cbica::CreateImage().

Referenced by cbica::CreateImage().

◆ CreateMaskIndeces()

std::vector< std::vector< typename TImageType::IndexType > > cbica::CreateMaskIndeces ( const std::vector< std::vector< typename TImageType::Pointer > > &  inputModalitiesAndImages)

Calculate and preserve the mask indeces.

Parameters
inputModalitiesAndImagesA collection of images which are stored in a per-modality basis (each entry corresponds to a subject, whose entries contain different modalities)
Returns
A collection of indeces which constitute the non-zero locations per modality (each entry corresponds to a subject, which contains the locations of non-zero pixel values for all modalities)

References cbica::CreateMaskIndeces().

Referenced by cbica::CreateMaskIndeces().

◆ GetAdaptiveHistogramEqualizedImage()

TImageType::Pointer cbica::GetAdaptiveHistogramEqualizedImage ( const typename TImageType::Pointer  inputImage,
const typename TImageType::Pointer  referenceImage,
const float  alpha = 0.3,
const float  beta = 0.3,
const float  radius = 1,
const int  numberOfHistogramLevels = 100 
)

Get the indeces of the image which are not zero.

Parameters
inputImageThe input image on which the matching needs to be done
referenceImageThe reference image based on which the
alphaRanges between 0-1; with 1 giving result same as input image and lower values behaving as unsharp filters; default = 0.3
betaRanges between 0-1; with 1 giving result same as input image and lower values behaving as unsharp filters; default = 0.3
radiusRanges between 1-10 with default = 1

References cbica::GetAdaptiveHistogramEqualizedImage().

Referenced by cbica::GetAdaptiveHistogramEqualizedImage().

◆ GetDistances()

itk::Vector< float, TImageType::ImageDimension > cbica::GetDistances ( const typename TImageType::Pointer  inputImage)

Get distances in world coordinates across axes for an image.

Parameters
inputImage

References cbica::GetDistances().

Referenced by cbica::GetDistances().

◆ GetHistogramMatchedImage()

TImageType::Pointer cbica::GetHistogramMatchedImage ( const typename TImageType::Pointer  inputImage,
const typename TImageType::Pointer  referenceImage,
const int  numberOfMatchPoints = 40,
const int  numberOfHistogramLevels = 100 
)

Get the indeces of the image which are not zero.

Parameters
inputImageThe input image on which the matching needs to be done
referenceImageThe reference image based on which the
numberOfMatchPointsGoverns the number of quantile values to be matched
numberOfHistogramLevelsSets the number of bins used when creating histograms of the source and reference images

References cbica::GetHistogramMatchedImage().

Referenced by cbica::GetHistogramMatchedImage().

◆ GetImageOrientation()

std::pair< std::string, typename TImageType::Pointer > cbica::GetImageOrientation ( const typename TImageType::Pointer  inputImage)

Perform the deformable registration.

Parameters
movingImageThe moving image for registration
referenceImageThe reference image for registration
multiResLevelsNumber of multi-resolution levels for registration, defaults to 5
iterationStartStart size of iteration for first multiResLevel, defaults to 10
iterationStepStep size of the iterations increasing over each MultiResLevel, defaults to 10
iterationEndEnd size of iteration for first multiResLevel, defaults to 50
regTypeThe type of registration to perform, defaults to 'Demons'
interpolatorTypeThe type of interpolator to use, defaults to 'Linear'Get the image orientation
inputImageThe input image
Returns
A pair of string (which represents the orientation) and an itk::Image which represents the inputImage in RAI form

References cbica::GetImageOrientation().

Referenced by cbica::GetImageOrientation().

◆ GetIndexFromNonZeroPixels()

std::vector< typename TImageType::IndexType > cbica::GetIndexFromNonZeroPixels ( const typename TImageType::Pointer  inputImage,
const std::string  valuesToExclude = "0" 
)

Get MD5 sum of a supplied file.

Parameters
fileNameThe input file
Returns
The MD5 checksumWrap of GetMD5Sum()Get the indeces of the image which are not zero

References cbica::GetIndexFromNonZeroPixels().

Referenced by cbica::GetIndexFromNonZeroPixels().

◆ GetMaxDistanceInLabelMap()

std::pair< float, typename TImageType::IndexType > cbica::GetMaxDistanceInLabelMap ( const typename TImageType::Pointer  inputLabelMap,
const typename TImageType::IndexType  indexForComputation,
bool  realCoordinateInput = false,
bool  realCoordinateOutput = false 
)

Get the maximum distance and corresponding coordinate from a seed point in a label map.

Parameters
inputLabelMapThe label map on which to do the calculation
indexForComputationThe index of the seed point from where to do the distance measurements
realCoordinatesPassedBool which denotes if indexForComputation is real (e.g. the tumorPoints used by GLISTR) or an image index
Returns
The maximum distance and the corrensponding index

References cbica::GetMaxDistanceInLabelMap().

Referenced by cbica::GetMaxDistanceInLabelMap().

◆ GetPixelValuesFromIndeces()

std::vector< typename TImageType::PixelType > cbica::GetPixelValuesFromIndeces ( const typename TImageType::Pointer  inputImage,
const std::vector< typename TImageType::IndexType > &  indeces 
)

Get Pixel Values of specified indeces of input Image.

Parameters
inputImageThe input image in itk::Image format
indecedThe indeces from which pixel values need to be extracted
Returns
Vector of values whose data type is the same as image type

References cbica::GetPixelValuesFromIndeces().

Referenced by cbica::GetPixelValuesFromIndeces().

◆ GetResultOfImageComparasion()

bool cbica::GetResultOfImageComparasion ( const typename TImageType::Pointer  referenceImage,
const typename TImageType::Pointer  checkImage,
const typename TImageType::PixelType  differenceThreshold = 0,
const unsigned int  toleranceRadius = 0,
const unsigned long long  numberOfPixelsTolerance = 10,
const typename TImageType::PixelType  averageIntensityDifference = 0 
)

Get result of Image comparison between 2 images.

This runs itk::Testing::ComparisonImageFilter inside so the inputs are identical. Always updates the largest possible region.

Parameters
referenceImageThe reference image for comparison
checkImageThe image to check
differenceThresholdThe minimum number of different pixels among both images; default is 0
toleranceRadiusThe maximum distance to look for a matching pixel; default is 0
numberOfPixelsToleranceThe maximum maximum number of pixels that can be different; default is 10
averageIntensityDifferenceThe maximum allowed average intensity difference between both images; default is 0
Returns
True if images are similar in accordance with passed parameters

References cbica::GetResultOfImageComparasion().

Referenced by cbica::GetResultOfImageComparasion().

◆ GetSkullStrippedImage()

TImageType::Pointer cbica::GetSkullStrippedImage ( const typename TImageType::Pointer  inputImage,
const typename TAtlasImageType::Pointer  atlasImage,
const typename TAtlasLabelType::Pointer  atlasLabelImage 
)

Get skull stripped image.

Templated over InputImageType, AtlasImageType and AtlasLabelType

Parameters
inputImageThe input image on which to run the skull stripping
atlasImageThe atlas image
atlasLabelImageThe atlas label

References cbica::GetSkullStrippedImage().

Referenced by cbica::GetSkullStrippedImage().

◆ GetUniqueValuesInImage()

std::vector< typename TImageType::PixelType > cbica::GetUniqueValuesInImage ( typename TImageType::Pointer  inputImage,
bool  sortResult = true 
)

Get the unique values in an image.

Parameters
inputImageThe input image
sortResultWhether the output should be sorted in ascending order or not, defaults to true

References cbica::GetUniqueValuesInImage().

Referenced by cbica::GetUniqueValuesInImage().

◆ ImageSanityCheck()

bool cbica::ImageSanityCheck ( const std::string &  image1,
const std::string &  image2 
)
inline

Check properties of 2 images to see if they are defined in the same space.

Checks are done based on cbica::ImageInfo class

References cbica::ImageSanityCheck().

◆ ResampleImage() [1/3]

TImageType::Pointer cbica::ResampleImage ( const typename TImageType::Pointer  inputImage,
const itk::Vector< double, TImageType::ImageDimension > &  outputSpacing,
const std::string  interpolator = "Linear" 
)

Resample an image to an isotropic resolution using the specified output spacing vector.

This filter uses the example https://itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter as a base while processing time-stamped images as well

Parameters
inputImageThe input image to process
outputSpacingThe output spacing, always isotropic
interpolatorThe type of interpolator to use; can be Linear, BSpline or NearestNeighbor
Returns
The resized image

References cbica::ResampleImage().

Referenced by cbica::ResampleImage().

◆ ResampleImage() [2/3]

TImageType::Pointer cbica::ResampleImage ( const typename TImageType::Pointer  inputImage,
const typename TImageType::SpacingType  outputSpacing,
typename TImageType::SizeType  outputSize,
const std::string  interpolator = "Linear" 
)

Resample an image to an isotropic resolution using the specified output spacing vector.

This filter uses the example https://itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter as a base while processing time-stamped images as well

Parameters
inputImageThe input image to process
outputSpacingThe output spacing, always isotropic
interpolatorThe type of interpolator to use; can be Linear, BSpline or NearestNeighbor
Returns
The resized image

References cbica::ResampleImage().

◆ ResampleImage() [3/3]

TImageType::Pointer cbica::ResampleImage ( const typename TImageType::Pointer  inputImage,
const float  outputSpacing = 1.0,
const std::string  interpolator = "Linear" 
)

Resample an image to an isotropic resolution using the specified output spacing.

This filter uses the example https://itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter as a base while processing time-stamped images as well

Parameters
inputImageThe input image to process
outputSpacingThe output spacing, always isotropic
interpolatorThe type of interpolator to use; can be Linear, BSpline or NearestNeighbor
Returns
The resized image

References cbica::ResampleImage().

◆ ResizeImage()

TImageType::Pointer cbica::ResizeImage ( const typename TImageType::Pointer  inputImage,
const size_t  resizeFactor,
const std::string &  interpolator = "Linear" 
)

Resize an input image by a factor (expressed as a percentage)

This filter uses the example https://itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter as a base while processing time-stamped images as well

Parameters
inputImageThe input image to process
resizeFactorThe resize factor; can be greater than 100 (which causes an expanded image to be written) but can never be less than zero
interpolatorThe type of interpolator to use; can be Linear, BSpline, BiCubic or NearestNeighbor
Returns
The resized image

References cbica::ResizeImage().

Referenced by cbica::ResizeImage().