22 #include <itkVectorImage.h> 23 #include <itkImageDuplicator.h> 24 #include <itkSpatialOrientationAdapter.h> 25 #include <itkRescaleIntensityImageFilter.h> 26 #include <itkAdaptiveHistogramEqualizationImageFilter.h> 27 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) //Review only members 28 #include <itkLabelImageToLabelMapFilter.h> 29 #include <itkLabelMapToLabelImageFilter.h> 30 #include <itkAutoCropLabelMapFilter.h> 31 #include <itkBinaryContourImageFilter.h> 32 #include <itkLabelContourImageFilter.h> 33 #include <itkLabelOverlayImageFilter.h> 34 #include <itkMergeLabelMapFilter.h> 35 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 36 #include <itkImportImageFilter.h> 37 #include <itkCastImageFilter.h> 38 #include <itkGradientMagnitudeRecursiveGaussianImageFilter.h> 39 #include <itkNormalizeImageFilter.h> 40 #include <itkInvertIntensityImageFilter.h> 41 #include <itkChangeInformationImageFilter.h> 42 #include <itkHistogramMatchingImageFilter.h> 43 #include <itkCheckerBoardImageFilter.h> 44 #include <itkDanielssonDistanceMapImageFilter.h> 45 #include <itkApproximateSignedDistanceMapImageFilter.h> 46 #include <itkSignedMaurerDistanceMapImageFilter.h> 47 #include <itkThresholdImageFilter.h> 48 #include <itkBinaryThresholdImageFilter.h> 49 #include <itkOtsuThresholdImageFilter.h> 50 #include <itkOtsuMultipleThresholdsImageFilter.h> 51 #include <itkMinimumMaximumImageCalculator.h> 52 #include <itkFlipImageFilter.h> 53 #include <itkConstantPadImageFilter.h> 54 #include <itkMaskImageFilter.h> 55 #include <itkGradientAnisotropicDiffusionImageFilter.h> 56 #include <itkBilateralImageFilter.h> 57 #include <itkSmoothingRecursiveGaussianImageFilter.h> 58 #include <itkSobelEdgeDetectionImageFilter.h> 59 #include <itkMedianImageFilter.h> 60 #include <itkLaplacianRecursiveGaussianImageFilter.h> 61 #include <itkCannyEdgeDetectionImageFilter.h> 62 #include <itkIdentityTransform.h> 63 #include <itkExtractImageFilter.h> 64 #include <itkVectorIndexSelectionCastImageFilter.h> 65 #include <itkResampleImageFilter.h> 66 #include <itkAffineTransform.h> 67 #include <itkVersorRigid3DTransform.h> 68 #include <itkCenteredEuler3DTransform.h> 69 #include <itkEuler3DTransform.h> 70 #include <itkTransformFileWriter.h> 71 #include <itkShrinkImageFilter.h> 72 #include <itkAddImageFilter.h> 73 #include <itkSubtractImageFilter.h> 74 #include <itkMultiplyImageFilter.h> 75 #include <itkRegionOfInterestImageFilter.h> 76 #include <itkNearestNeighborInterpolateImageFunction.h> 77 #include <itkBSplineInterpolateImageFunction.h> 78 #include <itkJoinSeriesImageFilter.h> 79 #include <itkConnectedComponentImageFilter.h> 80 #include <itkRelabelComponentImageFilter.h> 82 #if (ITK_VERSION_MAJOR > 3) 83 #include <itkv3Rigid3DTransform.h> 84 #include <itkFFTConvolutionImageFilter.h> 85 #include <itkVectorMagnitudeImageFilter.h> 87 #include <itkRigid3DTransform.h> 88 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) //Review only members 89 #include <itkConvolutionImageFilter.h> 91 #include <itkGradientToMagnitudeImageFilter.h> 94 #include "itkImageToVTKImageFilter.h" 95 #include "itkVTKImageToImageFilter.h" 98 #include <vtkMatrix4x4.h> 99 #include <vtkTransform.h> 100 #include <vtkImageReslice.h> 103 #include "itkVectorShiftScaleImageFilter.h" 105 #include "milxGlobal.h" 107 const double CoordinateTolerance = 1e-3;
108 const double DirectionTolerance = 1e-3;
173 template<
class TImage>
204 inline itk::SmartPointer<TImage>
Result()
216 return PreviousImage;
237 static vtkSmartPointer<vtkImageData> ConvertITKImageToVTKImage(itk::SmartPointer<TImage> img);
242 static vtkSmartPointer<vtkImageData> ConvertITKVectorImageToVTKImage(itk::SmartPointer<TImage> img);
244 template<
typename TRefImage,
class TPrecision>
245 static itk::SmartPointer<TImage> ApplyOrientationToITKImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TRefImage> refImage,
const bool labelledImage,
const bool flipY =
true,
const bool ignoreDirection =
false);
246 #ifndef ITK_ONLY //Requires VTK 259 static vtkSmartPointer<vtkImageData> ApplyOrientationToVTKImage(vtkSmartPointer<vtkImageData> img, itk::SmartPointer<TImage> refImage, vtkSmartPointer<vtkMatrix4x4> &transformMatrix,
const bool labelledImage,
const bool flipY =
true);
265 static itk::SmartPointer<TImage> ConvertVTKImageToITKImage(vtkSmartPointer<vtkImageData> img);
270 template<
typename TOutImage>
271 static itk::SmartPointer<TOutImage> CastImage(itk::SmartPointer<TImage> img);
281 static itk::SmartPointer<TImage> DuplicateImage(itk::SmartPointer<TImage> img);
286 static itk::SmartPointer<TImage> DuplicateImage(
const TImage *img);
293 template<
typename TVector>
294 static itk::SmartPointer<TImage> ImportVectorToImage(vnl_vector<TVector> &vec,
typename TImage::SizeType size, itk::SmartPointer<TImage> image = NULL);
301 template<
typename TMatrix>
302 static itk::SmartPointer<TImage> ImportMatrixToImage(vnl_matrix<TMatrix> &matrix, itk::SmartPointer<TImage> image = NULL);
308 static itk::SmartPointer<TImage> BlankImage(
typename TImage::PixelType value,
typename TImage::SizeType imgSize);
315 template<
typename TSubImage>
316 static itk::SmartPointer<TSubImage> ExtractSubImage(itk::SmartPointer<TImage> img,
typename TImage::RegionType imgRegion);
323 template<
typename TImageSlice>
324 static itk::SmartPointer<TImageSlice> ExtractSlice(itk::SmartPointer<TImage> img,
int *extent);
331 template<
typename TImageComponent>
332 static itk::SmartPointer<TImageComponent> ExtractComponent(itk::SmartPointer<TImage> img,
int component);
337 static itk::SmartPointer<TImage> ResizeImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType imgSize);
342 static itk::SmartPointer<TImage> ResizeImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType imgSize,
typename TImage::SpacingType outputSpacing);
347 static itk::SmartPointer<TImage> ResizeImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType imgSize,
typename TImage::SpacingType outputSpacing,
typename TImage::PointType outputOrigin,
typename TImage::DirectionType outputDirection);
355 static itk::SmartPointer<TImage> SubsampleImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType factors);
365 template<
typename TOutImage,
typename TTransform,
typename TPrecision>
366 static itk::SmartPointer<TOutImage> TransformImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TOutImage> refImg, itk::SmartPointer<TTransform> transf,
const bool inverse,
const int interp = 1);
367 template<
typename TOutImage,
typename TTransform,
typename TPrecision>
368 static itk::SmartPointer<TOutImage> TransformImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TTransform> transf,
const bool inverse,
const int interp = 1);
373 template<
typename TOutImage>
374 static itk::SmartPointer<TOutImage> ResampleImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TOutImage> refImg,
const bool linearInterp =
false);
379 template<
typename TOutImage>
380 static itk::SmartPointer<TOutImage> ResampleLabel(itk::SmartPointer<TImage> img, itk::SmartPointer<TOutImage> refImg);
387 static itk::SmartPointer<TImage> AddImages(itk::SmartPointer<TImage> img1, itk::SmartPointer<TImage> img2);
392 static itk::SmartPointer<TImage> SubtractImages(itk::SmartPointer<TImage> img1, itk::SmartPointer<TImage> img2);
397 static inline itk::SmartPointer<TImage>
DifferenceImages(itk::SmartPointer<TImage> img1, itk::SmartPointer<TImage> img2)
399 return SubtractImages(img1, img2);
405 static itk::SmartPointer<TImage> MultiplyImages(itk::SmartPointer<TImage> img1, itk::SmartPointer<TImage> img2);
410 template<
class TOutImage>
411 static itk::SmartPointer<TOutImage> ScaleImage(itk::SmartPointer<TImage> img,
float scaling);
416 static itk::SmartPointer<TImage> ScaleVectorImage(itk::SmartPointer<TImage> img,
float scaling,
int numberOfComponents);
417 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 424 static itk::SmartPointer<TImage> ConvolveImages(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> kernelImg);
425 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 432 static void Information(itk::SmartPointer<TImage> img);
437 static double ImageMaximum(itk::SmartPointer<TImage> img);
442 static double ImageMinimum(itk::SmartPointer<TImage> img);
447 static std::string ImageOrientation(itk::SmartPointer<TImage> img);
454 static itk::SmartPointer<TImage> CheckerBoard(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> imgToCheckerBoard,
const int numberOfSquares = 0);
459 static itk::SmartPointer<TImage> RescaleIntensity(itk::SmartPointer<TImage> img,
float minValue,
float maxValue);
464 static itk::SmartPointer<TImage> InvertIntensity(itk::SmartPointer<TImage> img,
float maxValue);
473 static itk::SmartPointer<TImage> HistogramEqualisation(itk::SmartPointer<TImage> img,
float alpha = 0.3,
float beta = 0.3,
float radius = 5);
478 static itk::SmartPointer<TImage> GradientMagnitude(itk::SmartPointer<TImage> img);
483 static itk::SmartPointer<TImage> SobelEdges(itk::SmartPointer<TImage> img);
488 static itk::SmartPointer<TImage> Laplacian(itk::SmartPointer<TImage> img);
493 static itk::SmartPointer<TImage> CannyEdges(itk::SmartPointer<TImage> img,
float variance,
float lowerThreshold,
float upperThreshold);
498 static itk::SmartPointer< itk::Image<float, TImage::ImageDimension> > Normalization(itk::SmartPointer<TImage> img);
506 static itk::SmartPointer<TImage> MatchInformation(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> imgToMatch,
bool originOnly =
false);
513 static itk::SmartPointer<TImage>
CopyInformation(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> imgToMatch,
bool originOnly =
false)
515 return MatchInformation(img, imgToMatch, originOnly);
522 static itk::SmartPointer<TImage> MatchHistogram(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> imgToMatch,
const int bins = 128);
531 template<
typename TOutImage>
532 static itk::SmartPointer<TOutImage> DistanceMap(itk::SmartPointer<TImage> img,
const bool binaryImage =
false,
const bool signedDistances =
false,
const bool computeInsideObject =
false,
const bool squaredDistance =
false);
537 static itk::SmartPointer<TImage> FlipImage(itk::SmartPointer<TImage> img,
bool xAxis =
false,
bool yAxis =
true,
bool zAxis =
false,
bool aboutOrigin =
true);
542 static itk::SmartPointer<TImage> PadImageByConstant(itk::SmartPointer<TImage> img,
size_t xAxis,
size_t yAxis,
size_t zAxis,
typename TImage::PixelType value);
547 template<
typename TOutImage>
548 static itk::SmartPointer<TOutImage> AnisotropicDiffusion(itk::SmartPointer<TImage> img,
const int iterations,
const float timestep);
553 static itk::SmartPointer<TImage> Bilateral(itk::SmartPointer<TImage> img,
const float sigmaRange,
const float sigmaSpatial);
558 static itk::SmartPointer<TImage> GaussianSmooth(itk::SmartPointer<TImage> img,
const float variance);
563 static itk::SmartPointer<TImage> Median(itk::SmartPointer<TImage> img,
const int radius);
570 template<
typename TMaskImage>
571 static itk::SmartPointer<TImage> MaskImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TMaskImage> maskImg);
576 static itk::SmartPointer<TImage> RelabelImage(itk::SmartPointer<TImage> labelledImg);
577 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 582 static itk::SmartPointer<TImage> BinaryContour(itk::SmartPointer<TImage> img,
const float foregroundValue,
const float backgroundValue);
587 static itk::SmartPointer<TImage> LabelContour(itk::SmartPointer<TImage> img,
const bool fullyConnected,
const float backgroundValue);
592 template<
typename TMaskImage>
593 static itk::SmartPointer<TImage> MaskAndCropImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TMaskImage> maskImg,
const size_t pixelPadding = 1);
598 static std::vector<unsigned char> LabelValues(itk::SmartPointer<TImage> labelledImg);
603 template<
typename TLabelImage>
604 static itk::SmartPointer< itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> > Overlay(itk::SmartPointer<TImage> img, itk::SmartPointer<TLabelImage> overlayImg);
609 template<
typename TLabelImage>
610 static itk::SmartPointer< itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> > OverlayContour(itk::SmartPointer<TImage> img, itk::SmartPointer<TLabelImage> overlayImg);
611 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 618 static itk::SmartPointer<TImage> ThresholdAboveImage(itk::SmartPointer<TImage> img,
float outsideValue,
float aboveValue);
623 static itk::SmartPointer<TImage> ThresholdBelowImage(itk::SmartPointer<TImage> img,
float outsideValue,
float aboveValue);
628 static itk::SmartPointer<TImage> ThresholdImage(itk::SmartPointer<TImage> img,
float outsideValue,
float belowValue,
float aboveValue);
633 template<
typename TOutImage>
634 static itk::SmartPointer<TOutImage> BinaryThresholdImage(itk::SmartPointer<TImage> img,
float outsideValue,
float insideValue,
float belowValue,
float aboveValue);
639 static double OtsuThreshold(itk::SmartPointer<TImage> img,
const int bins);
646 template<
typename TOutImage>
647 static itk::SmartPointer<TOutImage> OtsuThresholdImage(itk::SmartPointer<TImage> img,
const int bins);
654 template<
typename TOutImage>
655 static itk::SmartPointer<TOutImage> OtsuMultipleThresholdImage(itk::SmartPointer<TImage> img,
const int bins,
const int noOfLabels = 1);
662 template<
typename TScalarImage>
663 static itk::SmartPointer<TScalarImage> VectorMagnitude(itk::SmartPointer<TImage> img);
676 static void InformationCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
681 static void MatchHistogramCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TImage> refImage,
const int bins = 128);
686 static void CheckerboardCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TImage> refImage,
const int squares = 10);
691 static void RescaleIntensityCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
float belowValue,
float aboveValue);
696 static void InvertIntensityCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
701 static void FlipCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
bool xAxis =
false,
bool yAxis =
true,
bool zAxis =
false,
bool aboutOrigin =
true);
708 template<
typename TOutImage>
709 static std::vector< typename itk::SmartPointer<TOutImage> > AnisotropicDiffusionCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
const int iterations,
float timestep = -1.0);
714 static void BilateralCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
float sigmaRange,
float sigmaSpatial);
719 template<
typename TOutImage>
720 static std::vector< typename itk::SmartPointer<TOutImage> > CastCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images);
725 static void MedianCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
const int radius);
730 static void GradientMagnitudeCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
735 static void LaplacianCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
740 template<
typename TOutImage>
741 static std::vector< typename itk::SmartPointer<TOutImage> > DistanceMapCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
const bool binaryImage =
false,
const bool signedDistances =
false,
const bool computeInsideObject =
false,
const bool squaredDistance =
false);
748 static void ThresholdAboveCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
float outsideValue,
float aboveValue);
753 static void ThresholdBelowCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
float outsideValue,
float belowValue);
758 static void ThresholdCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
float outsideValue,
float belowValue,
float aboveValue);
763 template<
typename TOutImage>
764 static std::vector< typename itk::SmartPointer<TOutImage> > BinaryThresholdCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
float outsideValue,
float insideValue,
float belowValue,
float aboveValue);
769 template<
typename TOutImage>
770 static std::vector< typename itk::SmartPointer<TOutImage> > OtsuMultipleThresholdCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
const int bins,
const int noOfLabels);
772 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 777 template<
class TMaskImage>
778 static void MaskAndCropCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TMaskImage> maskImage,
const size_t pixelPadding = 1);
779 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 784 template<
class TMaskImage>
785 static void MaskCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TMaskImage> maskImage);
790 static void RelabelCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
795 template<
class TRefImage>
796 static void ResampleCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TRefImage> refImage);
801 template<
class TRefImage>
802 static void ResampleLabelCollection(std::vector<
typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TRefImage> refImage);
807 static itk::SmartPointer<TImage> AddCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
812 static itk::SmartPointer<TImage> SubtractCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
817 static inline itk::SmartPointer<TImage>
DifferenceCollection(std::vector<
typename itk::SmartPointer<TImage> > &images)
819 return SubtractCollection(images);
825 template<
class TOutImage>
826 static itk::SmartPointer<TOutImage> AverageCollection(std::vector<
typename itk::SmartPointer<TImage> > &images);
831 static itk::SmartPointer<TImage> AverageVectorCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
int numberOfComponents);
832 template<
class TJoinedImage>
833 itk::SmartPointer<TJoinedImage> JoinCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
const double origin,
const double spacing);
834 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 845 static itk::SmartPointer<TImage> MergeLabelledImages(std::vector<
typename itk::SmartPointer<TImage> > &images,
const size_t mergeType = 0);
846 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 857 template<
class TImage>
878 template<
class TImage>
881 typedef itk::ImageToVTKImageFilter<TImage> ConvertImageType;
883 typename ConvertImageType::Pointer convertFilter = ConvertImageType::New();
884 convertFilter->SetInput(img);
885 convertFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
888 convertFilter->Update();
890 catch (itk::ExceptionObject & ex )
892 PrintError(
"Failed Converting ITK Image to VTK Image");
896 return convertFilter->GetOutput();
899 template<
class TImage>
902 typedef itk::Image<typename TImage::InternalPixelType, TImage::ImageDimension> TImageComponent;
908 vtkSmartPointer<vtkImageData> field = vtkSmartPointer<vtkImageData>::New();
909 field->SetDimensions(fieldComponent->GetDimensions());
910 field->SetOrigin(fieldComponent->GetOrigin());
911 field->SetSpacing(fieldComponent->GetSpacing());
912 #if VTK_MAJOR_VERSION <= 5 913 field->SetNumberOfScalarComponents(img->GetNumberOfComponentsPerPixel());
914 field->SetScalarTypeToFloat();
915 field->AllocateScalars();
917 field->AllocateScalars(VTK_FLOAT, 3);
924 for(vtkIdType j = 0; j < img->GetNumberOfComponentsPerPixel(); j ++)
929 for(
int k = 0; k < fieldComponent->GetDimensions()[0]; k ++)
930 for(
int l = 0; l < fieldComponent->GetDimensions()[1]; l ++)
931 for(
int m = 0; m < fieldComponent->GetDimensions()[2]; m ++)
932 field->SetScalarComponentFromFloat(k, l, m, j, fieldComponentTmp->GetScalarComponentAsFloat(k, l, m, 0));
938 template<
class TImage>
939 template<
class TRefImage,
class TPrecision>
940 itk::SmartPointer<TImage>
Image<TImage>::ApplyOrientationToITKImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TRefImage> refImage,
const bool labelledImage,
const bool flipY,
const bool ignoreDirection)
942 typename TImage::DirectionType direction = refImage->GetDirection();
943 typename TImage::PointType origin = refImage->GetOrigin();
945 typedef itk::InterpolateImageFunction<TImage, TPrecision> InterpolatorType;
946 typename InterpolatorType::Pointer interpolator;
948 interpolator = itk::NearestNeighborInterpolateImageFunction<TImage, TPrecision>::New();
950 interpolator = itk::LinearInterpolateImageFunction<TImage, TPrecision>::New();
952 typedef itk::IdentityTransform<TPrecision, 3> TransformType;
953 typename TransformType::Pointer identityTransform = TransformType::New();
1006 typedef itk::ResampleImageFilter<TImage, TImage, TPrecision> ResampleImageFilterType;
1007 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1008 resample->SetInput(img);
1009 resample->SetDefaultPixelValue(0.0);
1010 resample->SetTransform(identityTransform);
1011 resample->SetSize(refImage->GetLargestPossibleRegion().GetSize());
1013 resample->SetOutputSpacing(refImage->GetSpacing());
1015 resample->SetInterpolator(interpolator);
1016 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1020 resample->UpdateLargestPossibleRegion();
1023 catch (itk::ExceptionObject & ex )
1025 PrintError(
"Failed applying orientation to Image");
1029 return resample->GetOutput();
1032 #ifndef ITK_ONLY //Requires VTK 1033 template<
class TImage>
1034 vtkSmartPointer<vtkImageData>
Image<TImage>::ApplyOrientationToVTKImage(vtkSmartPointer<vtkImageData> img, itk::SmartPointer<TImage> refImage, vtkSmartPointer<vtkMatrix4x4> &transformMatrix,
const bool labelledImage,
const bool flipY)
1036 typename TImage::DirectionType direction = refImage->GetDirection();
1037 typename TImage::PointType origin = refImage->GetOrigin();
1039 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
1041 for (
int i = 0; i < 3; i ++)
1042 for (
int k = 0; k < 3; k ++)
1043 matrix->SetElement(i,k, direction(i,k));
1044 matrix->Transpose();
1046 if(!transformMatrix)
1047 transformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
1048 transformMatrix->Identity();
1051 transformMatrix->SetElement(1,1,-1);
1053 vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
1054 transform->Identity();
1055 transform->PostMultiply();
1056 transform->Concatenate(transformMatrix);
1057 transform->Translate(-origin[0], -origin[1], -origin[2]);
1058 transform->Concatenate(matrix);
1059 transform->Translate(origin.GetDataPointer());
1061 vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
1062 #if VTK_MAJOR_VERSION <= 5 1063 reslice->SetInput(img);
1065 reslice->SetInputData(img);
1067 reslice->AddObserver(vtkCommand::ProgressEvent, VTKProgressUpdates);
1068 reslice->AutoCropOutputOn();
1069 reslice->TransformInputSamplingOn();
1070 reslice->SetOutputDimensionality(milx::imgDimension);
1071 reslice->SetResliceAxes(transform->GetMatrix());
1074 reslice->SetInterpolationModeToLinear();
1077 reslice->SetInterpolationModeToNearestNeighbor();
1078 PrintDebug(
"Using NN Interpolator for Image Orientation.");
1085 std::string resliceType = reslice->GetOutput()->GetScalarTypeAsString();
1086 PrintDebug(
"Orientated Image Type as " + resliceType);
1088 return reslice->GetOutput();
1092 template<
class TImage>
1095 typedef itk::VTKImageToImageFilter<TImage> ConvertImageType;
1097 typename ConvertImageType::Pointer convertFilter = ConvertImageType::New();
1098 convertFilter->SetInput(img);
1099 convertFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1102 convertFilter->Update();
1104 catch (itk::ExceptionObject & ex )
1106 PrintError(
"Failed Converting VTK Image to ITK Image");
1110 itk::SmartPointer<TImage> tmpImage = DuplicateImage(convertFilter->GetOutput());
1115 template<
class TImage>
1116 template<
typename TOutImage>
1119 typedef itk::CastImageFilter<TImage, TOutImage> CastImageType;
1121 typename CastImageType::Pointer castFilter = CastImageType::New();
1122 castFilter->SetInput(img);
1123 castFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1126 castFilter->Update();
1128 catch (itk::ExceptionObject & ex )
1134 return castFilter->GetOutput();
1151 template<
class TImage>
1154 typedef itk::ImageDuplicator<TImage> DuplicateType;
1156 typename DuplicateType::Pointer duplicator = DuplicateType::New();
1157 duplicator->SetInputImage(img);
1158 duplicator->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1161 duplicator->Update();
1163 catch (itk::ExceptionObject & ex )
1165 PrintError(
"Failed Generating Duplicate Image");
1169 return duplicator->GetOutput();
1172 template<
class TImage>
1175 typedef itk::ImageDuplicator<TImage> DuplicateType;
1177 typename DuplicateType::Pointer duplicator = DuplicateType::New();
1178 duplicator->SetInputImage(img);
1179 duplicator->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1182 duplicator->Update();
1184 catch (itk::ExceptionObject & ex )
1186 PrintError(
"Failed Generating Duplicate Image");
1190 return duplicator->GetOutput();
1193 template<
class TImage>
1194 template<
typename TVector>
1198 typedef itk::ImportImageFilter<typename TImage::PixelType, TImage::ImageDimension> ImportFilterType;
1199 typename ImportFilterType::Pointer importFilter = ImportFilterType::New();
1201 typename ImportFilterType::IndexType start;
1204 typename ImportFilterType::RegionType region;
1205 region.SetIndex(start);
1206 region.SetSize(size);
1208 importFilter->SetRegion( region );
1211 importFilter->SetOrigin( image->GetOrigin() );
1212 importFilter->SetSpacing( image->GetSpacing() );
1213 importFilter->SetDirection( image->GetDirection() );
1216 const bool importImageFilterWillOwnTheBuffer =
false;
1217 importFilter->SetImportPointer( vec.data_block(), vec.size(), importImageFilterWillOwnTheBuffer );
1218 importFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1221 importFilter->Update();
1223 catch (itk::ExceptionObject & ex )
1225 PrintError(
"Failed Converting vector to ITK Image");
1229 return importFilter->GetOutput();
1232 template<
class TImage>
1233 template<
typename TMatrix>
1237 typedef itk::ImportImageFilter<typename TImage::PixelType, TImage::ImageDimension> ImportFilterType;
1238 typename ImportFilterType::Pointer importFilter = ImportFilterType::New();
1240 typename ImportFilterType::SizeType size;
1241 size[0] = matrix.rows();
1242 size[1] = matrix.cols();
1245 typename ImportFilterType::IndexType start;
1248 typename ImportFilterType::RegionType region;
1249 region.SetIndex(start);
1250 region.SetSize(size);
1252 importFilter->SetRegion( region );
1255 importFilter->SetOrigin( image->GetOrigin() );
1256 importFilter->SetSpacing( image->GetSpacing() );
1257 importFilter->SetDirection( image->GetDirection() );
1260 const bool importImageFilterWillOwnTheBuffer =
false;
1261 importFilter->SetImportPointer( matrix.data_block(), matrix.size(), importImageFilterWillOwnTheBuffer );
1262 importFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1265 importFilter->Update();
1267 catch (itk::ExceptionObject & ex )
1269 PrintError(
"Failed Converting matrix to ITK Image");
1273 return importFilter->GetOutput();
1276 template<
class TImage>
1279 typename TImage::IndexType blankStart;
1282 typename TImage::RegionType blankRegion;
1283 blankRegion.SetIndex(blankStart);
1284 blankRegion.SetSize(imgSize);
1287 typename TImage::Pointer img = TImage::New();
1288 img->SetRegions(blankRegion);
1290 img->FillBuffer(value);
1296 template<
class TImage>
1297 template<
typename TSubImage>
1300 typedef itk::ExtractImageFilter<TImage, TSubImage> FilterType;
1301 typename FilterType::Pointer extractor = FilterType::New();
1302 extractor->SetExtractionRegion(imgRegion);
1303 extractor->SetInput(img);
1304 #if ITK_VERSION_MAJOR >= 4 1305 extractor->SetDirectionCollapseToIdentity();
1307 extractor->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1311 extractor->Update();
1313 catch (itk::ExceptionObject & ex )
1319 return extractor->GetOutput();
1322 template<
class TImage>
1323 template<
typename TImageSlice>
1326 typename TImage::IndexType desiredStart;
1327 desiredStart[0] = extent[0];
1328 desiredStart[1] = extent[2];
1329 desiredStart[2] = extent[4];
1332 typename TImage::SizeType desiredSize;
1333 desiredSize[0] = extent[1]-extent[0];
1334 desiredSize[1] = extent[3]-extent[2];
1335 desiredSize[2] = extent[5]-extent[4];
1337 const size_t sliceDim = TImageSlice::ImageDimension;
1338 const size_t imgDim = TImage::ImageDimension;
1340 if(sliceDim == imgDim)
1342 for(
size_t j = 0; j < imgDim; j ++)
1344 if(desiredSize[j] == 0)
1345 desiredSize[j] += 1;
1351 typename TImage::RegionType desiredRegion(desiredStart, desiredSize);
1353 return ExtractSubImage<TImageSlice>(img, desiredRegion);
1356 template<
class TImage>
1357 template<
typename TImageComponent>
1360 typedef itk::VectorIndexSelectionCastImageFilter<TImage, TImageComponent> IndexSelectionType;
1361 typename IndexSelectionType::Pointer indexSelectionFilter = IndexSelectionType::New();
1362 indexSelectionFilter->SetIndex(component);
1363 indexSelectionFilter->SetInput(img);
1367 indexSelectionFilter->Update();
1369 catch (itk::ExceptionObject & ex )
1375 return indexSelectionFilter->GetOutput();
1378 template<
class TImage>
1381 typedef itk::IdentityTransform<double, imgDimension> TransformType;
1382 typedef itk::ResampleImageFilter<TImage, TImage> ResampleImageFilterType;
1383 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1384 resample->SetInput(img);
1385 resample->SetSize(imgSize);
1386 resample->SetOutputSpacing(img->GetSpacing());
1387 resample->SetTransform(TransformType::New());
1388 resample->UpdateLargestPossibleRegion();
1389 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1395 catch (itk::ExceptionObject & ex )
1401 return resample->GetOutput();
1404 template<
class TImage>
1405 itk::SmartPointer<TImage>
Image<TImage>::ResizeImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType imgSize,
typename TImage::SpacingType outputSpacing)
1407 typedef itk::IdentityTransform<double, imgDimension> TransformType;
1408 typedef itk::ResampleImageFilter<TImage, TImage> ResampleImageFilterType;
1409 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1410 resample->SetInput(img);
1411 resample->SetSize(imgSize);
1412 resample->SetOutputSpacing(outputSpacing);
1413 resample->SetTransform(TransformType::New());
1414 resample->UpdateLargestPossibleRegion();
1415 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1421 catch (itk::ExceptionObject & ex )
1427 return resample->GetOutput();
1430 template<
class TImage>
1431 itk::SmartPointer<TImage>
Image<TImage>::ResizeImage(itk::SmartPointer<TImage> img,
typename TImage::SizeType imgSize,
typename TImage::SpacingType outputSpacing,
typename TImage::PointType outputOrigin,
typename TImage::DirectionType outputDirection)
1433 typedef itk::IdentityTransform<double, imgDimension> TransformType;
1434 typedef itk::ResampleImageFilter<TImage, TImage> ResampleImageFilterType;
1435 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1436 resample->SetInput(img);
1437 resample->SetSize(imgSize);
1438 resample->SetOutputSpacing(outputSpacing);
1439 resample->SetOutputOrigin(outputOrigin);
1440 resample->SetOutputDirection(outputDirection);
1441 resample->SetTransform(TransformType::New());
1442 resample->UpdateLargestPossibleRegion();
1443 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1449 catch (itk::ExceptionObject & ex )
1455 return resample->GetOutput();
1458 template<
class TImage>
1461 typedef itk::ShrinkImageFilter<TImage, TImage> SubSampleImageFilterType;
1462 typename SubSampleImageFilterType::Pointer subsample = SubSampleImageFilterType::New();
1463 subsample->SetInput(img);
1464 for(
size_t j = 0; j < TImage::ImageDimension; j ++)
1465 subsample->SetShrinkFactor(j, factors[j]);
1466 subsample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1470 subsample->Update();
1472 catch (itk::ExceptionObject & ex )
1478 return subsample->GetOutput();
1482 template<
class TImage>
1483 template<
typename TOutImage,
typename TTransform,
typename TPrecision>
1484 itk::SmartPointer<TOutImage>
Image<TImage>::TransformImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TOutImage> refImg, itk::SmartPointer<TTransform> transf,
const bool inverse,
const int interp)
1486 typedef itk::InterpolateImageFunction<TImage, TPrecision> InterpolatorType;
1487 typename InterpolatorType::Pointer interpolator;
1490 interpolator = itk::NearestNeighborInterpolateImageFunction<TImage, TPrecision>::New();
1491 PrintDebug(
"Using nearest neighbour interpolation for resampling.");
1493 else if(interp == 1)
1495 interpolator = itk::LinearInterpolateImageFunction<TImage, TPrecision>::New();
1496 PrintDebug(
"Using linear interpolation for resampling.");
1500 typedef itk::BSplineInterpolateImageFunction<TImage, TPrecision, TPrecision> BSplineInterpolatorType;
1501 typename BSplineInterpolatorType::Pointer bsplineInterpolator = BSplineInterpolatorType::New();
1502 bsplineInterpolator->SetSplineOrder(3);
1503 interpolator = bsplineInterpolator;
1504 PrintDebug(
"Using BSpline interpolation for resampling.");
1507 typedef itk::ResampleImageFilter<TImage, TOutImage, TPrecision> ResampleImageFilterType;
1508 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1509 resample->SetInput(img);
1510 resample->SetDefaultPixelValue(0.0);
1511 resample->UseReferenceImageOn();
1512 resample->SetReferenceImage(refImg);
1517 resample->SetInterpolator(interpolator);
1518 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1521 typedef itk::AffineTransform< TPrecision, milx::imgDimension > AffineTransformType;
1522 typedef typename AffineTransformType::Pointer AffineTransformPointer;
1523 typedef itk::VersorRigid3DTransform<TPrecision> VersorRigidTransformType;
1524 typedef typename VersorRigidTransformType::Pointer VersorRigidTransformPointer;
1525 #if ITK_VERSION_MAJOR > 3 //New() member issues, see ITK4 tests for detail 1526 typedef itkv3::Rigid3DTransform<TPrecision> RigidTransformType;
1528 typedef itk::Rigid3DTransform<TPrecision> RigidTransformType;
1530 typedef typename RigidTransformType::Pointer RigidTransformPointer;
1531 typedef itk::CenteredEuler3DTransform<TPrecision> CenteredEuler3DTransformType;
1532 typedef typename CenteredEuler3DTransformType::Pointer CenteredEuler3DTransformPointer;
1533 typedef itk::Euler3DTransform<TPrecision> Euler3DTransformType;
1534 typedef typename Euler3DTransformType::Pointer Euler3DTransformPointer;
1536 AffineTransformPointer affineTransform;
1537 VersorRigidTransformPointer versorRigidTransform;
1538 RigidTransformPointer rigidTransform;
1539 CenteredEuler3DTransformPointer centeredEulerTransform;
1540 Euler3DTransformPointer euler3DTransform;
1542 if( !strcmp(transf->GetNameOfClass(),
"AffineTransform") )
1544 AffineTransformPointer affine_read =
static_cast<AffineTransformType*
>(transf.GetPointer());
1545 affineTransform =
dynamic_cast< AffineTransformType *
>( affine_read.GetPointer() );
1546 if( affineTransform )
1548 PrintInfo(
"Successfully Read Affine Transform file.");
1549 AffineTransformPointer affineInvTransform;
1552 affineInvTransform = AffineTransformType::New();
1553 affineTransform->GetInverse(affineInvTransform);
1556 affineInvTransform = affineTransform;
1557 resample->SetTransform(affineInvTransform);
1560 else if( !strcmp(transf->GetNameOfClass(),
"VersorRigid3DTransform") )
1562 VersorRigidTransformPointer rigid_read =
static_cast<VersorRigidTransformType*
>(transf.GetPointer());
1563 versorRigidTransform =
dynamic_cast< VersorRigidTransformType *
>( rigid_read.GetPointer() );
1564 if( versorRigidTransform )
1566 PrintInfo(
"Successfully Read Versor Rigid Transform file.");
1567 VersorRigidTransformPointer versorRigidInvTransform;
1570 versorRigidInvTransform = VersorRigidTransformType::New();
1571 versorRigidTransform->GetInverse(versorRigidInvTransform);
1574 versorRigidInvTransform = versorRigidTransform;
1575 resample->SetTransform(versorRigidInvTransform);
1578 else if( !strcmp(transf->GetNameOfClass(),
"Rigid3DTransform") )
1580 RigidTransformPointer rigid_read =
static_cast<RigidTransformType*
>(transf.GetPointer());
1581 rigidTransform =
dynamic_cast< RigidTransformType *
>( rigid_read.GetPointer() );
1582 if( rigidTransform )
1584 PrintInfo(
"Successfully Read Rigid Transform file.");
1585 RigidTransformPointer rigidInvTransform;
1588 rigidInvTransform = RigidTransformType::New();
1589 rigidTransform->GetInverse(rigidInvTransform);
1592 rigidInvTransform = rigidTransform;
1593 resample->SetTransform(rigidInvTransform);
1596 else if( !strcmp(transf->GetNameOfClass(),
"CenteredEuler3DTransform") )
1598 CenteredEuler3DTransformPointer rigid_read =
static_cast<CenteredEuler3DTransformType*
>(transf.GetPointer());
1599 centeredEulerTransform =
dynamic_cast< CenteredEuler3DTransformType *
>( rigid_read.GetPointer() );
1600 if( centeredEulerTransform )
1602 PrintInfo(
"Successfully Read Centered Euler 3D Transform file.");
1603 CenteredEuler3DTransformPointer centeredEulerInvTransform;
1606 centeredEulerInvTransform = CenteredEuler3DTransformType::New();
1607 centeredEulerTransform->GetInverse(centeredEulerInvTransform);
1610 centeredEulerInvTransform = centeredEulerTransform;
1611 resample->SetTransform(centeredEulerInvTransform);
1614 else if( !strcmp(transf->GetNameOfClass(),
"Euler3DTransform") )
1616 Euler3DTransformPointer rigid_read =
static_cast<Euler3DTransformType*
>(transf.GetPointer());
1617 euler3DTransform =
dynamic_cast< Euler3DTransformType *
>( rigid_read.GetPointer() );
1618 if( euler3DTransform )
1620 PrintInfo(
"Successfully Read Euler 3D Transform file.");
1621 Euler3DTransformPointer euler3DInvTransform;
1624 euler3DInvTransform = Euler3DTransformType::New();
1625 euler3DTransform->GetInverse(euler3DInvTransform);
1628 euler3DInvTransform = euler3DTransform;
1629 resample->SetTransform(euler3DInvTransform);
1634 PrintError(
"milxImage: Transform Input is not of known type");
1641 catch (itk::ExceptionObject & ex )
1647 return resample->GetOutput();
1650 template<
class TImage>
1651 template<
typename TOutImage,
typename TTransform,
typename TPrecision>
1652 itk::SmartPointer<TOutImage>
Image<TImage>::TransformImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TTransform> transf,
const bool inverse,
const int interp)
1654 typedef itk::InterpolateImageFunction<TImage, TPrecision> InterpolatorType;
1655 typename InterpolatorType::Pointer interpolator;
1658 interpolator = itk::NearestNeighborInterpolateImageFunction<TImage, TPrecision>::New();
1659 PrintDebug(
"Using nearest neighbour interpolation for resampling.");
1661 else if(interp == 1)
1663 interpolator = itk::LinearInterpolateImageFunction<TImage, TPrecision>::New();
1664 PrintDebug(
"Using linear interpolation for resampling.");
1668 typedef itk::BSplineInterpolateImageFunction<TImage, TPrecision, TPrecision> BSplineInterpolatorType;
1669 typename BSplineInterpolatorType::Pointer bsplineInterpolator = BSplineInterpolatorType::New();
1670 bsplineInterpolator->SetSplineOrder(3);
1671 interpolator = bsplineInterpolator;
1672 PrintDebug(
"Using BSpline interpolation for resampling.");
1676 typename TImage::PointType transformedOrigin = transf->TransformPoint(img->GetOrigin());
1678 typedef itk::ResampleImageFilter<TImage, TOutImage, TPrecision> ResampleImageFilterType;
1679 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1682 typedef itk::AffineTransform< TPrecision, milx::imgDimension > AffineTransformType;
1683 typedef typename AffineTransformType::Pointer AffineTransformPointer;
1684 typedef itk::VersorRigid3DTransform<TPrecision> VersorRigidTransformType;
1685 typedef typename VersorRigidTransformType::Pointer VersorRigidTransformPointer;
1686 #if ITK_VERSION_MAJOR > 3 //New() member issues, see ITK4 tests for detail 1687 typedef itkv3::Rigid3DTransform<TPrecision> RigidTransformType;
1689 typedef itk::Rigid3DTransform<TPrecision> RigidTransformType;
1691 typedef typename RigidTransformType::Pointer RigidTransformPointer;
1692 typedef itk::CenteredEuler3DTransform<TPrecision> CenteredEuler3DTransformType;
1693 typedef typename CenteredEuler3DTransformType::Pointer CenteredEuler3DTransformPointer;
1694 typedef itk::Euler3DTransform<TPrecision> Euler3DTransformType;
1695 typedef typename Euler3DTransformType::Pointer Euler3DTransformPointer;
1697 AffineTransformPointer affineTransform;
1698 VersorRigidTransformPointer versorRigidTransform;
1699 RigidTransformPointer rigidTransform;
1700 CenteredEuler3DTransformPointer centeredEulerTransform;
1701 Euler3DTransformPointer euler3DTransform;
1703 if( !strcmp(transf->GetNameOfClass(),
"AffineTransform") )
1705 AffineTransformPointer affine_read =
static_cast<AffineTransformType*
>(transf.GetPointer());
1706 affineTransform =
dynamic_cast< AffineTransformType *
>( affine_read.GetPointer() );
1707 if( affineTransform )
1709 PrintInfo(
"Successfully Read Affine Transform file.");
1710 AffineTransformPointer affineInvTransform;
1713 affineInvTransform = AffineTransformType::New();
1714 affineTransform->GetInverse(affineInvTransform);
1717 affineInvTransform = affineTransform;
1718 resample->SetTransform(affineInvTransform);
1719 transformedOrigin = affineInvTransform->TransformPoint(img->GetOrigin());
1722 else if( !strcmp(transf->GetNameOfClass(),
"VersorRigid3DTransform") )
1724 VersorRigidTransformPointer rigid_read =
static_cast<VersorRigidTransformType*
>(transf.GetPointer());
1725 versorRigidTransform =
dynamic_cast< VersorRigidTransformType *
>( rigid_read.GetPointer() );
1726 if( versorRigidTransform )
1728 PrintInfo(
"Successfully Read Versor Rigid Transform file.");
1729 VersorRigidTransformPointer versorRigidInvTransform;
1732 versorRigidInvTransform = VersorRigidTransformType::New();
1733 versorRigidTransform->GetInverse(versorRigidInvTransform);
1736 versorRigidInvTransform = versorRigidTransform;
1737 resample->SetTransform(versorRigidInvTransform);
1738 transformedOrigin = versorRigidInvTransform->TransformPoint(img->GetOrigin());
1741 else if( !strcmp(transf->GetNameOfClass(),
"Rigid3DTransform") )
1743 RigidTransformPointer rigid_read =
static_cast<RigidTransformType*
>(transf.GetPointer());
1744 rigidTransform =
dynamic_cast< RigidTransformType *
>( rigid_read.GetPointer() );
1745 if( rigidTransform )
1747 PrintInfo(
"Successfully Read Rigid Transform file.");
1748 RigidTransformPointer rigidInvTransform;
1751 rigidInvTransform = RigidTransformType::New();
1752 rigidTransform->GetInverse(rigidInvTransform);
1755 rigidInvTransform = rigidTransform;
1756 resample->SetTransform(rigidInvTransform);
1757 transformedOrigin = rigidInvTransform->TransformPoint(img->GetOrigin());
1760 else if( !strcmp(transf->GetNameOfClass(),
"CenteredEuler3DTransform") )
1762 CenteredEuler3DTransformPointer rigid_read =
static_cast<CenteredEuler3DTransformType*
>(transf.GetPointer());
1763 centeredEulerTransform =
dynamic_cast< CenteredEuler3DTransformType *
>( rigid_read.GetPointer() );
1764 if( centeredEulerTransform )
1766 PrintInfo(
"Successfully Read Centered Euler 3D Transform file.");
1767 CenteredEuler3DTransformPointer centeredEulerInvTransform;
1770 centeredEulerInvTransform = CenteredEuler3DTransformType::New();
1771 centeredEulerTransform->GetInverse(centeredEulerInvTransform);
1774 centeredEulerInvTransform = centeredEulerTransform;
1775 resample->SetTransform(centeredEulerInvTransform);
1776 transformedOrigin = centeredEulerInvTransform->TransformPoint(img->GetOrigin());
1779 else if( !strcmp(transf->GetNameOfClass(),
"Euler3DTransform") )
1781 Euler3DTransformPointer rigid_read =
static_cast<Euler3DTransformType*
>(transf.GetPointer());
1782 euler3DTransform =
dynamic_cast< Euler3DTransformType *
>( rigid_read.GetPointer() );
1783 if( euler3DTransform )
1785 PrintInfo(
"Successfully Read Euler 3D Transform file.");
1786 Euler3DTransformPointer euler3DInvTransform;
1789 euler3DInvTransform = Euler3DTransformType::New();
1790 euler3DTransform->GetInverse(euler3DInvTransform);
1793 euler3DInvTransform = euler3DTransform;
1794 resample->SetTransform(euler3DInvTransform);
1795 transformedOrigin = euler3DInvTransform->TransformPoint(img->GetOrigin());
1800 PrintError(
"milxImage: Transform Input is not of known type");
1803 resample->SetInput(img);
1804 resample->SetDefaultPixelValue(0.0);
1805 resample->SetSize( img->GetLargestPossibleRegion().GetSize() );
1806 resample->SetOutputOrigin( transformedOrigin );
1807 resample->SetOutputSpacing( img->GetSpacing() );
1808 resample->SetOutputDirection( img->GetDirection() );
1809 resample->SetInterpolator(interpolator);
1810 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1815 catch (itk::ExceptionObject & ex )
1821 return resample->GetOutput();
1824 template<
class TImage>
1825 template<
typename TOutImage>
1829 typedef itk::InterpolateImageFunction<TImage, float> InterpolatorType;
1830 typename InterpolatorType::Pointer interpolator;
1833 interpolator = itk::LinearInterpolateImageFunction<TImage, float>::New();
1834 PrintDebug(
"Using linear interpolation for resampling.");
1838 typedef itk::BSplineInterpolateImageFunction<TImage, float, float> BSplineInterpolatorType;
1839 typename BSplineInterpolatorType::Pointer bsplineInterpolator = BSplineInterpolatorType::New();
1840 bsplineInterpolator->SetSplineOrder(3);
1841 interpolator = bsplineInterpolator;
1842 PrintDebug(
"Using BSpline interpolation for resampling.");
1845 typedef itk::ResampleImageFilter<TImage, TOutImage, float> ResampleImageFilterType;
1846 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1847 resample->SetInput(img);
1848 resample->SetDefaultPixelValue(0.0);
1849 resample->UseReferenceImageOn();
1850 resample->SetReferenceImage(refImg);
1855 resample->SetInterpolator(interpolator);
1856 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1866 resample->UpdateLargestPossibleRegion();
1869 catch (itk::ExceptionObject & ex )
1875 return resample->GetOutput();
1878 template<
class TImage>
1879 template<
typename TOutImage>
1883 typedef itk::NearestNeighborInterpolateImageFunction<TImage, float> NNInterpolatorType;
1884 typename NNInterpolatorType::Pointer interpolator = NNInterpolatorType::New();
1885 PrintDebug(
"Using Nearest Neighbour interpolation for resampling.");
1887 typedef itk::ResampleImageFilter<TImage, TOutImage, float> ResampleImageFilterType;
1888 typename ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
1889 resample->SetInput(img);
1890 resample->SetDefaultPixelValue(0.0);
1891 resample->UseReferenceImageOn();
1892 resample->SetReferenceImage(refImg);
1897 resample->SetInterpolator(interpolator);
1898 resample->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1908 resample->UpdateLargestPossibleRegion();
1911 catch (itk::ExceptionObject & ex )
1917 return resample->GetOutput();
1921 template<
class TImage>
1924 typedef itk::AddImageFilter<TImage, TImage> AddImageType;
1926 typename AddImageType::Pointer addFilter = AddImageType::New();
1927 addFilter->SetInput1(img1);
1928 addFilter->SetInput2(img2);
1929 addFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1932 addFilter->Update();
1934 catch (itk::ExceptionObject & ex )
1940 return addFilter->GetOutput();
1943 template<
class TImage>
1946 typedef itk::SubtractImageFilter<TImage, TImage> SubtractImageType;
1948 typename SubtractImageType::Pointer subtractFilter = SubtractImageType::New();
1949 subtractFilter->SetInput1(img1);
1950 subtractFilter->SetInput2(img2);
1951 subtractFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1954 subtractFilter->Update();
1956 catch (itk::ExceptionObject & ex )
1962 return subtractFilter->GetOutput();
1965 template<
class TImage>
1968 typedef itk::MultiplyImageFilter<TImage, TImage> MultiplyImageType;
1970 typename MultiplyImageType::Pointer multiplyFilter = MultiplyImageType::New();
1971 multiplyFilter->SetInput1(img1);
1972 multiplyFilter->SetInput2(img2);
1973 multiplyFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1976 multiplyFilter->Update();
1978 catch (itk::ExceptionObject & ex)
1984 return multiplyFilter->GetOutput();
1987 template<
class TImage>
1988 template<
class TOutImage>
1991 typedef itk::ShiftScaleImageFilter<TImage, TOutImage> ScaleImageType;
1993 typename ScaleImageType::Pointer scaleFilter = ScaleImageType::New();
1994 scaleFilter->SetInput(img);
1995 scaleFilter->SetScale(scaling);
1996 scaleFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
1999 scaleFilter->Update();
2001 catch (itk::ExceptionObject & ex )
2007 return scaleFilter->GetOutput();
2010 template<
class TImage>
2015 typename ScaleImageType::Pointer scaleFilter = ScaleImageType::New();
2016 scaleFilter->SetInput(img);
2017 scaleFilter->SetScale(scaling);
2018 scaleFilter->SetDimension(numberOfComponents);
2019 scaleFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2022 scaleFilter->Update();
2024 catch (itk::ExceptionObject & ex )
2030 return scaleFilter->GetOutput();
2033 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 2034 template<
class TImage>
2037 #if ITK_VERSION_MAJOR > 3 2038 typedef itk::FFTConvolutionImageFilter<TImage, TImage> ConvolveImageType;
2040 typedef itk::ConvolutionImageFilter<TImage, TImage> ConvolveImageType;
2043 typename ConvolveImageType::Pointer convolveFilter = ConvolveImageType::New();
2044 convolveFilter->SetInput(img);
2045 #if ITK_VERSION_MAJOR > 3 2046 convolveFilter->SetKernelImage(kernelImg);
2048 convolveFilter->SetImageKernelInput(kernelImg);
2050 convolveFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2053 convolveFilter->Update();
2055 catch (itk::ExceptionObject & ex )
2061 return convolveFilter->GetOutput();
2063 #endif //(ITK_REVIEW || ITK_VERSION_MAJOR > 3) 2066 template<
class TImage>
2069 typename TImage::DirectionType direction = img->GetDirection();
2070 typename TImage::PointType origin = img->GetOrigin();
2071 typename TImage::SpacingType spacing = img->GetSpacing();
2072 typename TImage::SizeType imageSize = img->GetLargestPossibleRegion().GetSize();
2074 std::cout <<
"Origin: ";
2075 for (
typename TImage::SizeValueType j = 0; j < TImage::ImageDimension; j++)
2077 std::cout <<
"\nSpacing: ";
2078 for (
typename TImage::SizeValueType j = 0; j < TImage::ImageDimension; j++)
2080 std::cout <<
"\nSize: ";
2081 for (
typename TImage::SizeValueType j = 0; j < TImage::ImageDimension; j++)
2083 std::cout <<
"\nReal Size: ";
2084 for (
typename TImage::SizeValueType j = 0; j < TImage::ImageDimension; j++)
2086 std::cout <<
"\nDirection/Orientation: " << std::endl;
2087 for (
typename TImage::SizeValueType j = 0; j < TImage::ImageDimension; j++)
2090 for (
typename TImage::SizeValueType k = 0; k < TImage::ImageDimension; k++)
2093 if (k < TImage::ImageDimension - 1)
2096 std::cout <<
" |" << std::endl;
2098 std::cout <<
"\nOrientation Flag: " << ImageOrientation(img) << std::endl;
2101 template<
class TImage>
2104 typedef itk::MinimumMaximumImageCalculator<TImage> ImageCalculatorFilterType;
2105 typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
2106 imageCalculatorFilter->SetImage(img);
2107 imageCalculatorFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2108 imageCalculatorFilter->Compute();
2110 return imageCalculatorFilter->GetMaximum();
2113 template<
class TImage>
2116 typedef itk::MinimumMaximumImageCalculator<TImage> ImageCalculatorFilterType;
2117 typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
2118 imageCalculatorFilter->SetImage(img);
2119 imageCalculatorFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2120 imageCalculatorFilter->Compute();
2122 return imageCalculatorFilter->GetMinimum();
2125 template<
class TImage>
2128 std::map<itk::SpatialOrientation::ValidCoordinateOrientationFlags, std::string> codeToString;
2130 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_AIL] =
"AIL";
2131 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL] =
"ASL";
2132 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI] =
"RAI";
2133 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LAI] =
"LAI";
2134 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RPS] =
"RPS";
2135 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LPS] =
"LPS";
2136 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIP] =
"RIP";
2137 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LIP] =
"LIP";
2138 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSP] =
"RSP";
2139 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LSP] =
"LSP";
2140 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIA] =
"RIA";
2141 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LIA] =
"LIA";
2142 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA] =
"RSA";
2143 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LSA] =
"LSA";
2144 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRP] =
"IRP";
2145 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ILP] =
"ILP";
2146 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SRP] =
"SRP";
2147 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SLP] =
"SLP";
2148 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRA] =
"IRA";
2149 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ILA] =
"ILA";
2150 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SRA] =
"SRA";
2151 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SLA] =
"SLA";
2152 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RPI] =
"RPI";
2153 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LPI] =
"LPI";
2154 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAS] =
"RAS";
2155 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LAS] =
"LAS";
2156 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PRI] =
"PRI";
2157 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PLI] =
"PLI";
2158 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ARI] =
"ARI";
2159 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ALI] =
"ALI";
2160 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PRS] =
"PRS";
2161 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PLS] =
"PLS";
2162 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ARS] =
"ARS";
2163 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ALS] =
"ALS";
2164 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IPR] =
"IPR";
2165 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SPR] =
"SPR";
2166 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IAR] =
"IAR";
2167 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SAR] =
"SAR";
2168 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IPL] =
"IPL";
2169 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SPL] =
"SPL";
2170 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IAL] =
"IAL";
2171 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_SAL] =
"SAL";
2172 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PIR] =
"PIR";
2173 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PSR] =
"PSR";
2174 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_AIR] =
"AIR";
2175 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASR] =
"ASR";
2176 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PIL] =
"PIL";
2177 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_PSL] =
"PSL";
2178 codeToString[itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_INVALID] =
"Unknown";
2180 itk::SpatialOrientation::ValidCoordinateOrientationFlags orientFlag = itk::SpatialOrientationAdapter().FromDirectionCosines(img->GetDirection());
2181 std::string orientFlagStr = codeToString[orientFlag];
2183 return orientFlagStr;
2187 template<
class TImage>
2188 itk::SmartPointer<TImage>
Image<TImage>::CheckerBoard(itk::SmartPointer<TImage> img, itk::SmartPointer<TImage> imgToCheckerBoard,
const int numberOfSquares)
2190 typedef itk::CheckerBoardImageFilter<TImage> CheckerBoardType;
2191 typename CheckerBoardType::Pointer checkerBoardFilter = CheckerBoardType::New();
2192 checkerBoardFilter->SetInput1(img);
2193 checkerBoardFilter->SetInput2(imgToCheckerBoard);
2194 if(numberOfSquares != 0)
2196 typename CheckerBoardType::PatternArrayType squares = checkerBoardFilter->GetCheckerPattern();
2197 squares.Fill(numberOfSquares);
2198 checkerBoardFilter->SetCheckerPattern(squares);
2200 checkerBoardFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2203 checkerBoardFilter->Update();
2205 catch (itk::ExceptionObject & ex )
2207 PrintError(
"Failed Generating Checker Board");
2211 return checkerBoardFilter->GetOutput();
2214 template<
class TImage>
2217 typedef itk::RescaleIntensityImageFilter< TImage, TImage > RescaleFilterType;
2218 typename RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
2219 rescaleFilter->SetInput(img);
2220 rescaleFilter->SetOutputMinimum(minValue);
2221 rescaleFilter->SetOutputMaximum(maxValue);
2222 rescaleFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2225 rescaleFilter->Update();
2227 catch (itk::ExceptionObject & ex )
2233 return rescaleFilter->GetOutput();
2236 template<
class TImage>
2239 typedef itk::InvertIntensityImageFilter<TImage, TImage> InvertIntensityImageFilterType;
2240 typename InvertIntensityImageFilterType::Pointer invert = InvertIntensityImageFilterType::New();
2241 invert->SetInput(img);
2242 invert->SetMaximum(maxValue);
2243 invert->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2248 catch (itk::ExceptionObject & ex )
2250 PrintError(
"Failed Computing Invert Intensity");
2254 return invert->GetOutput();
2257 template<
class TImage>
2260 typename TImage::SizeType radii;
2262 typedef itk::AdaptiveHistogramEqualizationImageFilter<TImage> EqualiseFilterType;
2263 typename EqualiseFilterType::Pointer equaliseFilter = EqualiseFilterType::New();
2264 equaliseFilter->SetInput(img);
2265 equaliseFilter->SetAlpha(alpha);
2266 equaliseFilter->SetBeta(beta);
2267 equaliseFilter->SetRadius(radii);
2268 equaliseFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2271 equaliseFilter->Update();
2273 catch (itk::ExceptionObject & ex )
2279 return equaliseFilter->GetOutput();
2282 template<
class TImage>
2285 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<TImage, TImage> GradImageFilterType;
2286 typename GradImageFilterType::Pointer gradientMagnitudeFilter = GradImageFilterType::New();
2287 gradientMagnitudeFilter->SetInput(img);
2288 gradientMagnitudeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2291 gradientMagnitudeFilter->Update();
2293 catch (itk::ExceptionObject & ex )
2295 PrintError(
"Failed Computing Gradient Magnitude");
2299 return gradientMagnitudeFilter->GetOutput();
2302 template<
class TImage>
2305 typedef itk::SobelEdgeDetectionImageFilter<TImage, TImage> SobelImageFilterType;
2306 typename SobelImageFilterType::Pointer sobelEdgeFilter = SobelImageFilterType::New();
2307 sobelEdgeFilter->SetInput(img);
2308 sobelEdgeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2311 sobelEdgeFilter->Update();
2313 catch (itk::ExceptionObject & ex )
2319 return sobelEdgeFilter->GetOutput();
2322 template<
class TImage>
2325 typedef itk::LaplacianRecursiveGaussianImageFilter<TImage, TImage> LaplacianImageFilterType;
2326 typename LaplacianImageFilterType::Pointer laplacianEdgeFilter = LaplacianImageFilterType::New();
2327 laplacianEdgeFilter->SetInput(img);
2328 laplacianEdgeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2331 laplacianEdgeFilter->Update();
2333 catch (itk::ExceptionObject & ex )
2339 return laplacianEdgeFilter->GetOutput();
2342 template<
class TImage>
2343 itk::SmartPointer<TImage>
Image<TImage>::CannyEdges(itk::SmartPointer<TImage> img,
float variance,
float lowerThreshold,
float upperThreshold)
2345 typedef itk::CannyEdgeDetectionImageFilter<TImage, TImage> CannyImageFilterType;
2346 typename CannyImageFilterType::Pointer cannyEdgeFilter = CannyImageFilterType::New();
2347 cannyEdgeFilter->SetInput(img);
2348 cannyEdgeFilter->SetVariance( variance );
2349 cannyEdgeFilter->SetUpperThreshold( upperThreshold );
2350 cannyEdgeFilter->SetLowerThreshold( lowerThreshold );
2351 cannyEdgeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2354 cannyEdgeFilter->Update();
2356 catch (itk::ExceptionObject & ex )
2362 return cannyEdgeFilter->GetOutput();
2365 template<
class TImage>
2368 typedef itk::NormalizeImageFilter< TImage, itk::Image<float, TImage::ImageDimension> > NormalizeImageFilterType;
2369 typename NormalizeImageFilterType::Pointer normalizeFilter = NormalizeImageFilterType::New();
2370 normalizeFilter->SetInput(img);
2371 normalizeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2374 normalizeFilter->Update();
2376 catch (itk::ExceptionObject & ex )
2378 PrintError(
"Failed Computing Normalization");
2382 return normalizeFilter->GetOutput();
2385 template<
class TImage>
2388 typedef itk::ChangeInformationImageFilter<TImage> ChangeInfoImageFilterType;
2389 typename ChangeInfoImageFilterType::Pointer change = ChangeInfoImageFilterType::New();
2390 change->SetInput(img);
2391 change->SetReferenceImage(imgToMatch);
2392 change->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2393 change->UseReferenceImageOn();
2396 change->ChangeDirectionOn();
2397 change->ChangeSpacingOn();
2398 change->ChangeRegionOn();
2402 change->ChangeDirectionOff();
2403 change->ChangeSpacingOff();
2404 change->ChangeRegionOff();
2406 change->ChangeOriginOn();
2411 catch (itk::ExceptionObject & ex )
2417 return change->GetOutput();
2420 template<
class TImage>
2423 typedef itk::HistogramMatchingImageFilter <TImage, TImage> MatchingFilterType;
2424 typename MatchingFilterType::Pointer matcher = MatchingFilterType::New();
2425 matcher->SetInput(img);
2426 matcher->SetReferenceImage(imgToMatch);
2427 matcher->SetNumberOfHistogramLevels(bins);
2428 matcher->SetNumberOfMatchPoints(7);
2429 matcher->ThresholdAtMeanIntensityOn();
2430 matcher->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2435 catch (itk::ExceptionObject & ex )
2441 return matcher->GetOutput();
2444 template<
class TImage>
2445 template<
typename TOutImage>
2446 itk::SmartPointer<TOutImage>
Image<TImage>::DistanceMap(itk::SmartPointer<TImage> img,
const bool binaryImage,
const bool signedDistances,
const bool computeInsideObject,
const bool squaredDistance)
2448 typedef itk::ImageToImageFilter<TImage, TOutImage> ImageFilterType;
2450 typename ImageFilterType::Pointer filter;
2451 if(computeInsideObject)
2453 typedef itk::ApproximateSignedDistanceMapImageFilter<TImage, TOutImage> DistanceMapImageFilterType;
2454 typename DistanceMapImageFilterType::Pointer distanceMapFilter = DistanceMapImageFilterType::New();
2455 filter = distanceMapFilter;
2457 else if(signedDistances)
2459 typedef itk::SignedMaurerDistanceMapImageFilter<TImage, TOutImage> DistanceMapImageFilterType;
2460 typename DistanceMapImageFilterType::Pointer distanceMapFilter = DistanceMapImageFilterType::New();
2461 distanceMapFilter->UseImageSpacingOn();
2462 if(!squaredDistance)
2463 distanceMapFilter->SquaredDistanceOff();
2465 distanceMapFilter->SquaredDistanceOn();
2466 filter = distanceMapFilter;
2470 typedef itk::DanielssonDistanceMapImageFilter<TImage, TOutImage> DistanceMapImageFilterType;
2471 typename DistanceMapImageFilterType::Pointer distanceMapFilter = DistanceMapImageFilterType::New();
2472 distanceMapFilter->UseImageSpacingOn();
2474 distanceMapFilter->InputIsBinaryOff();
2476 distanceMapFilter->InputIsBinaryOn();
2477 if(!squaredDistance)
2478 distanceMapFilter->SquaredDistanceOff();
2480 distanceMapFilter->SquaredDistanceOn();
2481 filter = distanceMapFilter;
2485 filter->SetInput(img);
2486 filter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2491 catch (itk::ExceptionObject & ex )
2497 return filter->GetOutput();
2500 template<
class TImage>
2501 itk::SmartPointer<TImage>
Image<TImage>::FlipImage(itk::SmartPointer<TImage> img,
bool xAxis,
bool yAxis,
bool zAxis,
bool aboutOrigin)
2503 itk::FixedArray<bool, imgDimension> flipAxes;
2504 flipAxes[0] = xAxis;
2505 flipAxes[1] = yAxis;
2506 flipAxes[2] = zAxis;
2509 typedef itk::FlipImageFilter<TImage> FlipImageFilterType;
2510 typename FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New();
2511 flipFilter->SetInput(img);
2512 flipFilter->SetFlipAxes(flipAxes);
2514 flipFilter->FlipAboutOriginOn();
2516 flipFilter->FlipAboutOriginOff();
2517 flipFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2520 flipFilter->Update();
2522 catch (itk::ExceptionObject & ex )
2528 return flipFilter->GetOutput();
2531 template<
class TImage>
2534 typename TImage::SizeType lowerExtendRegion;
2535 lowerExtendRegion[0] = xAxis;
2536 lowerExtendRegion[1] = yAxis;
2537 lowerExtendRegion[2] = zAxis;
2539 typename TImage::SizeType upperExtendRegion;
2540 upperExtendRegion[0] = xAxis;
2541 upperExtendRegion[1] = yAxis;
2542 upperExtendRegion[2] = zAxis;
2544 typename TImage::PixelType constantPixel = value;
2546 typedef itk::ConstantPadImageFilter<TImage, TImage> ConstantPadImageFilterType;
2547 typename ConstantPadImageFilterType::Pointer padFilter = ConstantPadImageFilterType::New();
2548 padFilter->SetInput(img);
2549 padFilter->SetPadLowerBound(lowerExtendRegion);
2550 padFilter->SetPadUpperBound(upperExtendRegion);
2551 padFilter->SetConstant(constantPixel);
2552 padFilter->Update();
2553 padFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2556 padFilter->Update();
2558 catch (itk::ExceptionObject & ex )
2564 return padFilter->GetOutput();
2567 template<
class TImage>
2568 template<
typename TOutImage>
2571 typedef itk::GradientAnisotropicDiffusionImageFilter<TImage, TOutImage> GradientAnisotropicDiffusionImageFilterType;
2572 typename GradientAnisotropicDiffusionImageFilterType::Pointer gradAniDiff = GradientAnisotropicDiffusionImageFilterType::New();
2573 gradAniDiff->SetInput(img);
2574 gradAniDiff->SetUseImageSpacing(
true);
2575 gradAniDiff->SetTimeStep(timestep);
2577 gradAniDiff->SetNumberOfIterations(iterations);
2578 gradAniDiff->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2582 gradAniDiff->Update();
2584 catch (itk::ExceptionObject & ex )
2586 PrintError(
"Failed Computing Invert Intensity");
2590 return gradAniDiff->GetOutput();
2593 template<
class TImage>
2596 typedef itk::BilateralImageFilter<TImage, TImage> BilateralImageFilterType;
2597 typename BilateralImageFilterType::Pointer bilateralFilter = BilateralImageFilterType::New();
2598 bilateralFilter->SetInput(img);
2599 bilateralFilter->SetRangeSigma(sigmaRange);
2600 bilateralFilter->SetDomainSigma(sigmaSpatial);
2601 bilateralFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2604 bilateralFilter->Update();
2606 catch (itk::ExceptionObject & ex )
2608 PrintError(
"Failed Computing Bilateral Smoothing");
2612 return bilateralFilter->GetOutput();
2615 template<
class TImage>
2618 typedef itk::SmoothingRecursiveGaussianImageFilter<TImage, TImage> GuassianImageFilterType;
2619 typename GuassianImageFilterType::Pointer smoothGaussian = GuassianImageFilterType::New();
2620 smoothGaussian->SetInput(img);
2621 smoothGaussian->SetSigma(variance);
2622 smoothGaussian->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2625 smoothGaussian->Update();
2627 catch (itk::ExceptionObject & ex )
2629 PrintError(
"Failed Computing Gaussian Smoothing");
2633 return smoothGaussian->GetOutput();
2636 template<
class TImage>
2639 typedef itk::MedianImageFilter<TImage, TImage> MedianImageFilterType;
2640 typename MedianImageFilterType::Pointer medianFilter = MedianImageFilterType::New();
2641 medianFilter->SetInput(img);
2642 typename MedianImageFilterType::InputSizeType radiusInput;
2643 radiusInput.Fill(radius);
2644 medianFilter->SetRadius(radiusInput);
2645 medianFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2648 medianFilter->Update();
2650 catch (itk::ExceptionObject & ex )
2656 return medianFilter->GetOutput();
2660 template<
class TImage>
2661 template<
typename TMaskImage>
2664 typedef itk::MaskImageFilter<TImage, TMaskImage> MaskFilterType;
2665 typename MaskFilterType::Pointer maskFilter = MaskFilterType::New();
2666 maskFilter->SetInput(img);
2667 maskFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2668 #if ITK_VERSION_MAJOR > 3 2669 maskFilter->SetCoordinateTolerance(CoordinateTolerance);
2670 maskFilter->SetDirectionTolerance(DirectionTolerance);
2671 maskFilter->SetMaskImage(maskImg);
2673 maskFilter->SetInput2(maskImg);
2678 maskFilter->Update();
2680 catch (itk::ExceptionObject & ex )
2686 return maskFilter->GetOutput();
2689 template<
class TImage>
2692 typedef itk::ConnectedComponentImageFilter<TImage, TImage> ConnectedComponentImageFilterType;
2693 typedef itk::RelabelComponentImageFilter<TImage, TImage> RelabelImageType;
2695 typename ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New ();
2696 connected->SetInput(labelledImg);
2698 typename RelabelImageType::Pointer relabelImageFilter = RelabelImageType::New();
2699 relabelImageFilter->SetInput(connected->GetOutput());
2703 relabelImageFilter->Update();
2705 catch (itk::ExceptionObject & ex )
2711 return relabelImageFilter->GetOutput();
2714 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 2715 template<
class TImage>
2716 itk::SmartPointer<TImage>
Image<TImage>::BinaryContour(itk::SmartPointer<TImage> img,
const float foregroundValue,
const float backgroundValue)
2718 typedef itk::BinaryContourImageFilter<TImage, TImage> BinaryContourType;
2720 typename BinaryContourType::Pointer contourFilter = BinaryContourType::New();
2721 contourFilter->SetInput(img);
2722 contourFilter->SetForegroundValue(foregroundValue);
2723 contourFilter->SetBackgroundValue(backgroundValue);
2724 contourFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2727 contourFilter->Update();
2729 catch (itk::ExceptionObject & ex )
2735 return contourFilter->GetOutput();
2738 template<
class TImage>
2739 itk::SmartPointer<TImage>
Image<TImage>::LabelContour(itk::SmartPointer<TImage> img,
const bool fullyConnected,
const float backgroundValue)
2741 typedef itk::LabelContourImageFilter<TImage, TImage> LabelContourType;
2743 typename LabelContourType::Pointer contourFilter = LabelContourType::New();
2744 contourFilter->SetInput(img);
2745 contourFilter->SetFullyConnected(fullyConnected);
2746 contourFilter->SetBackgroundValue(backgroundValue);
2747 contourFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2750 contourFilter->Update();
2752 catch (itk::ExceptionObject & ex )
2754 PrintError(
"Failed Generating Label Contours");
2758 return contourFilter->GetOutput();
2761 template<
class TImage>
2762 template<
typename TMaskImage>
2763 itk::SmartPointer<TImage>
Image<TImage>::MaskAndCropImage(itk::SmartPointer<TImage> img, itk::SmartPointer<TMaskImage> maskImg,
const size_t pixelPadding)
2765 typedef itk::LabelObject<unsigned char, TImage::ImageDimension> LabelObjectType;
2766 typedef itk::LabelMap<LabelObjectType> LabelMapType;
2768 typedef itk::LabelImageToLabelMapFilter<TMaskImage, LabelMapType> Image2LabelMapType;
2769 typename Image2LabelMapType::Pointer img2label = Image2LabelMapType::New();
2770 img2label->SetInput(maskImg);
2771 img2label->SetBackgroundValue(0);
2773 typedef itk::AutoCropLabelMapFilter<LabelMapType> AutoCropType;
2774 typename AutoCropType::Pointer autoCropper = AutoCropType::New();
2775 autoCropper->SetInput(img2label->GetOutput());
2776 typename AutoCropType::SizeType padSize = {{pixelPadding, pixelPadding, pixelPadding}};
2777 autoCropper->SetCropBorder(padSize);
2778 autoCropper->Update();
2780 typename AutoCropType::SizeType actualPadSize = autoCropper->GetCropBorder();
2783 return ExtractSubImage<TImage>(img, autoCropper->GetRegion());
2786 template<
class TImage>
2789 typedef itk::LabelObject<unsigned char, milx::imgDimension> LabelObjectType;
2790 typedef itk::LabelMap<LabelObjectType> LabelMapType;
2791 typedef itk::LabelImageToLabelMapFilter<TImage, LabelMapType> LabelImageToLabelMapType;
2793 typename LabelImageToLabelMapType::Pointer labelImageToLabelMapFilter = LabelImageToLabelMapType::New();
2794 labelImageToLabelMapFilter->SetInput(labelledImg);
2795 labelImageToLabelMapFilter->Update();
2796 typename LabelMapType::Pointer labelMap = labelImageToLabelMapFilter->GetOutput();
2798 std::vector<unsigned char> labelValues = labelMap->GetLabels();
2799 std::cout <<
"Found " << labelMap->GetNumberOfLabelObjects() << std::endl;
2804 template<
class TImage>
2805 template<
typename TLabelImage>
2806 itk::SmartPointer< itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> >
Image<TImage>::Overlay(itk::SmartPointer<TImage> img, itk::SmartPointer<TLabelImage> overlayImg)
2808 itk::SmartPointer<TImage> rescaledImg = RescaleIntensity(img, 0.0, 255.0);
2810 typedef unsigned char charPixelType;
2811 typedef itk::Image<charPixelType, TImage::ImageDimension> charImageType;
2813 typedef itk::CastImageFilter<TLabelImage, charImageType> CastImageType;
2814 typename CastImageType::Pointer castFilter = CastImageType::New();
2815 castFilter->SetInput(overlayImg);
2816 castFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2819 castFilter->Update();
2821 catch (itk::ExceptionObject & ex )
2828 typedef itk::LabelOverlayImageFilter< TImage, charImageType, itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> > OverlayType;
2829 typename OverlayType::Pointer overlayFilter = OverlayType::New();
2830 overlayFilter->SetInput( rescaledImg );
2831 overlayFilter->SetLabelImage( castFilter->GetOutput() );
2832 overlayFilter->SetOpacity( 0.6 );
2833 overlayFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2836 overlayFilter->Update();
2838 catch (itk::ExceptionObject & ex )
2844 return overlayFilter->GetOutput();
2847 template<
class TImage>
2848 template<
typename TLabelImage>
2849 itk::SmartPointer< itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> >
Image<TImage>::OverlayContour(itk::SmartPointer<TImage> img, itk::SmartPointer<TLabelImage> overlayImg)
2851 itk::SmartPointer<TImage> rescaledImg = RescaleIntensity(img, 0.0, 255.0);
2853 typedef unsigned char charPixelType;
2854 typedef itk::Image<charPixelType, TImage::ImageDimension> charImageType;
2856 typedef itk::LabelContourImageFilter<TLabelImage, charImageType> LabelContourType;
2857 typename LabelContourType::Pointer contourFilter = LabelContourType::New();
2858 contourFilter->SetInput(overlayImg);
2859 contourFilter->SetFullyConnected(
true);
2860 contourFilter->SetBackgroundValue(0.0);
2861 contourFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2864 contourFilter->Update();
2866 catch (itk::ExceptionObject & ex )
2868 PrintError(
"Failed Generating Label Contours in Overlay");
2873 typedef itk::LabelOverlayImageFilter< TImage, charImageType, itk::Image<itk::RGBPixel<unsigned char>, TImage::ImageDimension> > OverlayType;
2874 typename OverlayType::Pointer overlayFilter = OverlayType::New();
2875 overlayFilter->SetInput( rescaledImg );
2876 overlayFilter->SetLabelImage( contourFilter->GetOutput() );
2877 overlayFilter->SetOpacity( 0.6 );
2878 overlayFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2881 overlayFilter->Update();
2883 catch (itk::ExceptionObject & ex )
2885 PrintError(
"Failed Generating Overlay Contour");
2889 return overlayFilter->GetOutput();
2891 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 2894 template<
class TImage>
2897 typedef itk::ThresholdImageFilter<TImage> ThresholdImageFilterType;
2898 typename ThresholdImageFilterType::Pointer thresholding = ThresholdImageFilterType::New();
2899 thresholding->SetInput(img);
2900 thresholding->SetOutsideValue(outsideValue);
2901 thresholding->ThresholdAbove(aboveValue);
2902 thresholding->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2905 thresholding->Update();
2907 catch (itk::ExceptionObject & ex )
2913 return thresholding->GetOutput();
2916 template<
class TImage>
2919 typedef itk::ThresholdImageFilter<TImage> ThresholdImageFilterType;
2920 typename ThresholdImageFilterType::Pointer thresholding = ThresholdImageFilterType::New();
2921 thresholding->SetInput(img);
2922 thresholding->SetOutsideValue(outsideValue);
2923 thresholding->ThresholdBelow(belowValue);
2924 thresholding->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2927 thresholding->Update();
2929 catch (itk::ExceptionObject & ex )
2935 return thresholding->GetOutput();
2938 template<
class TImage>
2941 typedef itk::ThresholdImageFilter<TImage> ThresholdImageFilterType;
2942 typename ThresholdImageFilterType::Pointer thresholding = ThresholdImageFilterType::New();
2943 thresholding->SetInput(img);
2944 thresholding->SetOutsideValue(outsideValue);
2945 thresholding->ThresholdOutside(belowValue, aboveValue);
2946 thresholding->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2949 thresholding->Update();
2951 catch (itk::ExceptionObject & ex )
2957 return thresholding->GetOutput();
2960 template<
class TImage>
2961 template<
typename TOutImage>
2964 typedef itk::BinaryThresholdImageFilter<TImage, TOutImage> ThresholdImageFilterType;
2965 typename ThresholdImageFilterType::Pointer thresholding = ThresholdImageFilterType::New();
2966 thresholding->SetInput(img);
2967 thresholding->SetOutsideValue(outsideValue);
2968 thresholding->SetInsideValue(insideValue);
2969 thresholding->SetLowerThreshold(belowValue);
2970 thresholding->SetUpperThreshold(aboveValue);
2971 thresholding->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2974 thresholding->Update();
2976 catch (itk::ExceptionObject & ex )
2982 return thresholding->GetOutput();
2985 template<
class TImage>
2988 typedef itk::OtsuThresholdImageFilter<TImage, TImage> OtsuThresholdImageCalculatorType;
2989 typename OtsuThresholdImageCalculatorType::Pointer otsuThresholdImageCalculator = OtsuThresholdImageCalculatorType::New();
2990 otsuThresholdImageCalculator->SetInput(img);
2991 otsuThresholdImageCalculator->SetNumberOfHistogramBins(bins);
2992 otsuThresholdImageCalculator->AddObserver(itk::ProgressEvent(), ProgressUpdates);
2995 otsuThresholdImageCalculator->Update();
2997 catch (itk::ExceptionObject & ex )
2999 PrintError(
"Failed Computing Otsu Threshold");
3004 return otsuThresholdImageCalculator->GetThreshold();
3007 template<
class TImage>
3008 template<
typename TOutImage>
3011 typedef itk::OtsuThresholdImageFilter<TImage, TOutImage> OtsuThresholdImageCalculatorType;
3012 typename OtsuThresholdImageCalculatorType::Pointer otsuThresholdImageCalculator = OtsuThresholdImageCalculatorType::New();
3013 otsuThresholdImageCalculator->SetInput(img);
3014 otsuThresholdImageCalculator->SetNumberOfHistogramBins(bins);
3015 otsuThresholdImageCalculator->AddObserver(itk::ProgressEvent(), ProgressUpdates);
3018 otsuThresholdImageCalculator->Update();
3020 catch (itk::ExceptionObject & ex )
3022 PrintError(
"Failed Computing Otsu Threshold of Image");
3028 return otsuThresholdImageCalculator->GetOutput();
3031 template<
class TImage>
3032 template<
typename TOutImage>
3035 typedef itk::OtsuMultipleThresholdsImageFilter<TImage, TOutImage> OtsuThresholdImageType;
3036 typename OtsuThresholdImageType::Pointer otsuThresholdImageCalculator = OtsuThresholdImageType::New();
3037 otsuThresholdImageCalculator->SetInput(img);
3038 otsuThresholdImageCalculator->SetNumberOfHistogramBins(bins);
3039 otsuThresholdImageCalculator->SetNumberOfThresholds(noOfLabels);
3040 otsuThresholdImageCalculator->SetLabelOffset(0);
3041 otsuThresholdImageCalculator->AddObserver(itk::ProgressEvent(), ProgressUpdates);
3044 otsuThresholdImageCalculator->Update();
3046 catch (itk::ExceptionObject & ex )
3048 PrintError(
"Failed Computing Otsu Multiple Threshold");
3052 typename OtsuThresholdImageType::ThresholdVectorType thresholds = otsuThresholdImageCalculator->GetThresholds();
3053 std::string thresholdStrs;
3054 for(
size_t j = 0; j < thresholds.size(); j ++)
3056 PrintDebug(
"Otsu Thresholds - " + thresholdStrs);
3058 return otsuThresholdImageCalculator->GetOutput();
3061 template<
class TImage>
3062 template<
typename TScalarImage>
3065 #if (ITK_VERSION_MAJOR > 3) 3066 typedef itk::VectorMagnitudeImageFilter<TImage, TScalarImage> MagnitudeImageFilterType;
3068 typedef itk::GradientToMagnitudeImageFilter<TImage, TScalarImage> MagnitudeImageFilterType;
3070 typename MagnitudeImageFilterType::Pointer magnitudeFilter = MagnitudeImageFilterType::New();
3071 magnitudeFilter->SetInput(img);
3072 magnitudeFilter->AddObserver(itk::ProgressEvent(), ProgressUpdates);
3075 magnitudeFilter->Update();
3077 catch (itk::ExceptionObject & ex )
3079 PrintError(
"Failed Computing Magnitude of Image");
3083 return magnitudeFilter->GetOutput();
3087 template<
class TImage>
3090 const size_t n = images.size();
3092 for(
size_t j = 0; j < n; j ++)
3094 Information(images[j]);
3095 std::cout << std::endl;
3099 template<
class TImage>
3102 const size_t n = images.size();
3104 for(
size_t j = 0; j < n; j ++)
3105 images[j] = MatchHistogram(images[j], refImage, bins);
3108 template<
class TImage>
3111 const size_t n = images.size();
3113 for(
size_t j = 0; j < n; j ++)
3114 images[j] = CheckerBoard(images[j], refImage, squares);
3117 template<
class TImage>
3120 const size_t n = images.size();
3122 for(
size_t j = 0; j < n; j ++)
3123 images[j] = RescaleIntensity(images[j], belowValue, aboveValue);
3126 template<
class TImage>
3129 const size_t n = images.size();
3131 for(
size_t j = 0; j < n; j ++)
3133 float maxValue = ImageMaximum(images[j]);
3134 images[j] = InvertIntensity(images[j], maxValue);
3138 template<
class TImage>
3141 const size_t n = images.size();
3143 for(
size_t j = 0; j < n; j ++)
3145 images[j] = FlipImage(images[j], xAxis, yAxis, zAxis, aboutOrigin);
3149 template<
class TImage>
3150 template<
typename TOutImage>
3153 const size_t n = images.size();
3155 std::vector< itk::SmartPointer<TOutImage> > collection;
3156 for(
size_t j = 0; j < n; j ++)
3158 typename TImage::SizeType imgSize = images[j]->GetLargestPossibleRegion().GetSize();
3162 size_t maxDimension = 0;
3163 for(
size_t k = 0; k < imgSize.GetSizeDimension(); k ++)
3165 if(imgSize[k] > maxDimension)
3166 maxDimension = imgSize[k];
3169 timestep = 2.0/maxDimension;
3172 itk::SmartPointer<TOutImage> newImage = AnisotropicDiffusion<TOutImage>(images[j], iterations, timestep);
3173 collection.push_back(newImage);
3179 template<
class TImage>
3182 const size_t n = images.size();
3184 for(
size_t j = 0; j < n; j ++)
3185 images[j] = Bilateral(images[j], sigmaRange, sigmaSpatial);
3188 template<
class TImage>
3189 template<
typename TOutImage>
3192 const size_t n = images.size();
3194 std::vector< itk::SmartPointer<TOutImage> > collection;
3195 for(
size_t j = 0; j < n; j ++)
3197 itk::SmartPointer<TOutImage> newImage = CastImage<TOutImage>(images[j]);
3198 collection.push_back(newImage);
3204 template<
class TImage>
3207 const size_t n = images.size();
3209 for(
size_t j = 0; j < n; j ++)
3210 images[j] = Median(images[j], radius);
3213 template<
class TImage>
3216 const size_t n = images.size();
3218 for(
size_t j = 0; j < n; j ++)
3219 images[j] = GradientMagnitude(images[j]);
3222 template<
class TImage>
3225 const size_t n = images.size();
3227 for(
size_t j = 0; j < n; j ++)
3228 images[j] = Laplacian(images[j]);
3231 template<
class TImage>
3232 template<
typename TOutImage>
3233 std::vector< typename itk::SmartPointer<TOutImage> >
Image<TImage>::DistanceMapCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
const bool binaryImage,
const bool signedDistances,
const bool computeInsideObject,
const bool squaredDistance)
3235 const size_t n = images.size();
3237 std::vector< itk::SmartPointer<TOutImage> > collection;
3238 for(
size_t j = 0; j < n; j ++)
3240 itk::SmartPointer<TOutImage> newImage = DistanceMap<TOutImage>(images[j], binaryImage, signedDistances, computeInsideObject, squaredDistance);
3241 collection.push_back(newImage);
3248 template<
class TImage>
3251 const size_t n = images.size();
3253 for(
size_t j = 0; j < n; j ++)
3254 images[j] = ThresholdAboveImage(images[j], outsideValue, aboveValue);
3257 template<
class TImage>
3260 const size_t n = images.size();
3262 for(
size_t j = 0; j < n; j ++)
3263 images[j] = ThresholdBelowImage(images[j], outsideValue, belowValue);
3266 template<
class TImage>
3269 const size_t n = images.size();
3271 for(
size_t j = 0; j < n; j ++)
3272 images[j] = ThresholdImage(images[j], outsideValue, belowValue, aboveValue);
3275 template<
class TImage>
3276 template<
typename TOutImage>
3277 std::vector< typename itk::SmartPointer<TOutImage> >
Image<TImage>::BinaryThresholdCollection(
const std::vector<
typename itk::SmartPointer<TImage> > &images,
float outsideValue,
float insideValue,
float belowValue,
float aboveValue)
3279 const size_t n = images.size();
3281 std::vector< itk::SmartPointer<TOutImage> > collection;
3282 for(
size_t j = 0; j < n; j ++)
3284 itk::SmartPointer<TOutImage> newImage = BinaryThresholdImage<TOutImage>(images[j], outsideValue, insideValue, belowValue, aboveValue);
3285 collection.push_back(newImage);
3291 template<
class TImage>
3292 template<
typename TOutImage>
3295 const size_t n = images.size();
3297 std::vector< itk::SmartPointer<TOutImage> > collection;
3298 for(
size_t j = 0; j < n; j ++)
3300 itk::SmartPointer<TOutImage> newImage = OtsuMultipleThresholdImage<TOutImage>(images[j], bins, noOfLabels);
3301 collection.push_back(newImage);
3307 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 3308 template<
class TImage>
3309 template<
class TMaskImage>
3312 const size_t n = images.size();
3314 for(
size_t j = 0; j < n; j ++)
3315 images[j] = MaskAndCropImage<TMaskImage>(images[j], maskImage, pixelPadding);
3317 #endif // (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 3319 template<
class TImage>
3320 template<
class TMaskImage>
3323 const size_t n = images.size();
3325 for(
size_t j = 0; j < n; j ++)
3326 images[j] = MaskImage<TMaskImage>(images[j], maskImage);
3329 template<
class TImage>
3332 const size_t n = images.size();
3334 for(
size_t j = 0; j < n; j ++)
3335 images[j] = RelabelImage(images[j]);
3338 template<
class TImage>
3339 template<
class TRefImage>
3342 const size_t n = images.size();
3344 for(
size_t j = 0; j < n; j ++)
3345 images[j] = ResampleImage<TRefImage>(images[j], refImage);
3348 template<
class TImage>
3349 template<
class TRefImage>
3352 const size_t n = images.size();
3354 for(
size_t j = 0; j < n; j ++)
3355 images[j] = ResampleLabel<TRefImage>(images[j], refImage);
3358 template<
class TImage>
3361 const size_t n = images.size();
3363 itk::SmartPointer<TImage> result = DuplicateImage(images[0]);
3364 for(
size_t j = 1; j < n; j ++)
3365 result = AddImages(result, images[j]);
3370 template<
class TImage>
3373 const size_t n = images.size();
3375 itk::SmartPointer<TImage> result = DuplicateImage(images[0]);
3376 for(
size_t j = 1; j < n; j ++)
3377 result = SubtractImages(result, images[j]);
3382 template<
class TImage>
3383 template<
class TOutImage>
3386 const size_t n = images.size();
3388 itk::SmartPointer<TImage> sumImg = AddCollection(images);
3389 itk::SmartPointer<TOutImage> averageImg = ScaleImage<TOutImage>(sumImg, 1.0/n);
3394 template<
class TImage>
3397 const size_t n = images.size();
3399 itk::SmartPointer<TImage> sumImg = AddCollection(images);
3400 itk::SmartPointer<TImage> averageImg = ScaleVectorImage(sumImg, 1.0/n, numberOfComponents);
3405 template<
class TImage>
3406 template<
class TJoinedImage>
3407 itk::SmartPointer<TJoinedImage>
Image<TImage>::JoinCollection(std::vector<
typename itk::SmartPointer<TImage> > &images,
const double origin,
const double spacing)
3409 const size_t n = images.size();
3411 typedef itk::JoinSeriesImageFilter<TImage, TJoinedImage> JoinSeriesFilterType;
3412 typename JoinSeriesFilterType::Pointer joinSeries = JoinSeriesFilterType::New();
3413 joinSeries->SetOrigin(origin);
3414 joinSeries->SetSpacing(spacing);
3415 for(
size_t j = 0; j < n; j ++)
3416 joinSeries->PushBackInput(images[j]);
3419 joinSeries->Update();
3421 catch (itk::ExceptionObject & ex )
3427 return joinSeries->GetOutput();
3430 #if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) 3431 template<
class TImage>
3434 const size_t n = images.size();
3436 typedef itk::LabelObject<unsigned char, milx::imgDimension> LabelObjectType;
3437 typedef itk::LabelMap<LabelObjectType> LabelMapType;
3438 typedef itk::LabelImageToLabelMapFilter<TImage, LabelMapType> LabelImageToLabelMapType;
3439 typedef itk::MergeLabelMapFilter<LabelMapType> MergerType;
3440 typename MergerType::Pointer merger = MergerType::New();
3442 merger->SetMethod(MergerType::KEEP);
3443 else if(mergeType == 1)
3444 merger->SetMethod(MergerType::AGGREGATE);
3445 else if(mergeType == 2)
3446 merger->SetMethod(MergerType::PACK);
3447 else if(mergeType == 3)
3448 merger->SetMethod(MergerType::STRICT);
3450 for (
size_t i = 0; i < n; i ++)
3452 typename LabelImageToLabelMapType::Pointer labelImageToLabelMapFilter = LabelImageToLabelMapType::New();
3453 labelImageToLabelMapFilter->SetInput(images[i]);
3454 labelImageToLabelMapFilter->Update();
3456 std::cout <<
"Found " << labelImageToLabelMapFilter->GetOutput()->GetNumberOfLabelObjects() <<
" in the labelled image " << i << std::endl;
3458 merger->SetInput(i, labelImageToLabelMapFilter->GetOutput());
3465 catch (itk::ExceptionObject & ex )
3467 PrintError(
"Failed Merging Labelled Images");
3472 typedef itk::LabelMapToLabelImageFilter<LabelMapType, TImage> LabelMapToLabelImageType;
3473 typename LabelMapToLabelImageType::Pointer labelMapToLabelImageFilter = LabelMapToLabelImageType::New();
3474 labelMapToLabelImageFilter->SetInput(merger->GetOutput());
3475 labelMapToLabelImageFilter->Update();
3477 return labelMapToLabelImageFilter->GetOutput();
3483 #endif //__MILXIMAGE_H void PrintDebug(const std::string msg)
Displays a generic msg to standard error with carriage return if in Debug mode.
static itk::SmartPointer< TOutImage > BinaryThresholdImage(itk::SmartPointer< TImage > img, float outsideValue, float insideValue, float belowValue, float aboveValue)
Generates a binary image thresholded at the intensities below and above a certain level to the outsid...
static void FlipCollection(std::vector< typename itk::SmartPointer< TImage > > &images, bool xAxis=false, bool yAxis=true, bool zAxis=false, bool aboutOrigin=true)
Batch process images by flipping each image along axis provided.
static itk::SmartPointer< TImage > SubtractCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by the subtracting the images from the first image (pixel-wise).
static itk::SmartPointer< TOutImage > AnisotropicDiffusion(itk::SmartPointer< TImage > img, const int iterations, const float timestep)
Generates the gradient anisotropic diffusion (smoothing) of an image using the number of iterations...
static itk::SmartPointer< TImage > MultiplyImages(itk::SmartPointer< TImage > img1, itk::SmartPointer< TImage > img2)
Multiplies (element-wise) image 2 from image 1, returning the result.
static double ImageMaximum(itk::SmartPointer< TImage > img)
Returns the maximum pixel value of an image.
static itk::SmartPointer< TImage > ThresholdImage(itk::SmartPointer< TImage > img, float outsideValue, float belowValue, float aboveValue)
Generates an image with the intensities below and above a certain level thresholded (capped) to the o...
static itk::SmartPointer< TOutImage > ScaleImage(itk::SmartPointer< TImage > img, float scaling)
Scales the image intensities by scaling factor and returns the result.
static itk::SmartPointer< TOutImage > OtsuMultipleThresholdImage(itk::SmartPointer< TImage > img, const int bins, const int noOfLabels=1)
Generates the multiple Otsu threshold of an image of given the number of histogram bins...
virtual ~Image()
Standard Destructor.
static vtkSmartPointer< vtkImageData > ConvertITKImageToVTKImage(itk::SmartPointer< TImage > img)
Converts a ITK image object to an VTK image object. You MUST DeepCopy the result as the ITK smartpoin...
static void MedianCollection(std::vector< typename itk::SmartPointer< TImage > > &images, const int radius)
Batch process images by smoothing each image using the Median of the neighbourhood.
static itk::SmartPointer< TOutImage > CastImage(itk::SmartPointer< TImage > img)
Casts an image from one type to another.
static itk::SmartPointer< TImage > ConvertVTKImageToITKImage(vtkSmartPointer< vtkImageData > img)
Converts a VTK image object to an ITK image object.
itk::SmartPointer< TImage > PreviousImage
Holds the previous image in the pipeline.
static itk::SmartPointer< TImage > RelabelImage(itk::SmartPointer< TImage > labelledImg)
Returns a labelled image with labelled values relabelled consecutively based on connectivity.
static double ImageMinimum(itk::SmartPointer< TImage > img)
Returns the minimum pixel value of an image.
static std::vector< typename itk::SmartPointer< TOutImage > > AnisotropicDiffusionCollection(const std::vector< typename itk::SmartPointer< TImage > > &images, const int iterations, float timestep=-1.0)
Batch process images by smoothing each image using Gradient Anisotropic Diffusion.
static itk::SmartPointer< TImage > CheckerBoard(itk::SmartPointer< TImage > img, itk::SmartPointer< TImage > imgToCheckerBoard, const int numberOfSquares=0)
Generates a checker board pattern where each box alternates between two images. Ideal for comparison ...
Image()
Standard constructor.
void PrintError(const std::string msg)
Displays a generic msg to standard error with carriage return.
static itk::SmartPointer< TOutImage > ResampleLabel(itk::SmartPointer< TImage > img, itk::SmartPointer< TOutImage > refImg)
Resample the a labelled image into a new reference image space given ensuring no interpolator artefac...
static void ThresholdAboveCollection(std::vector< typename itk::SmartPointer< TImage > > &images, float outsideValue, float aboveValue)
Batch process images by thresholding each image from above.
static vtkSmartPointer< vtkImageData > ConvertITKVectorImageToVTKImage(itk::SmartPointer< TImage > img)
Converts a ITK Vector image object to an VTK image object. You MUST DeepCopy the result as the ITK sm...
static itk::SmartPointer< TImage > CopyInformation(itk::SmartPointer< TImage > img, itk::SmartPointer< TImage > imgToMatch, bool originOnly=false)
Changes the image info to match that of provided image. By default, only the spacing, region and origin are changed.
static itk::SmartPointer< TScalarImage > VectorMagnitude(itk::SmartPointer< TImage > img)
Generates an image comprised of the magnitude of the vectors in the image.
static itk::SmartPointer< TImage > SubtractImages(itk::SmartPointer< TImage > img1, itk::SmartPointer< TImage > img2)
Subtracts image 2 from image 1, returning the result.
static itk::SmartPointer< TImageSlice > ExtractSlice(itk::SmartPointer< TImage > img, int *extent)
Extract a sub image (such as a slice) from the current image given the extent (typically obtained fro...
static itk::SmartPointer< TImage > GradientMagnitude(itk::SmartPointer< TImage > img)
Generates an image with the gradient magnitude of the given image.
itk::SmartPointer< TImage > CurrentImage
Holds the current image in the pipeline.
Base class for images that contains non-templated features so to allow dynamic template instantiation...
static void ThresholdCollection(std::vector< typename itk::SmartPointer< TImage > > &images, float outsideValue, float belowValue, float aboveValue)
Batch process images by thresholding each image within band provided.
#define SMILI_EXPORT
DLL Function Symbol for Windows. It is empty for other OSes.
static itk::SmartPointer< TImage > ThresholdAboveImage(itk::SmartPointer< TImage > img, float outsideValue, float aboveValue)
Generates an image with the intensities above a certain level thresholded (capped) to the outsideValu...
static itk::SmartPointer< TImage > ImportVectorToImage(vnl_vector< TVector > &vec, typename TImage::SizeType size, itk::SmartPointer< TImage > image=NULL)
Imports a VNL vector to an ITK image object.
static void BilateralCollection(std::vector< typename itk::SmartPointer< TImage > > &images, float sigmaRange, float sigmaSpatial)
Batch process images by bilateral smoothing each image.
static itk::SmartPointer< TOutImage > OtsuThresholdImage(itk::SmartPointer< TImage > img, const int bins)
Generates the Otsu threshold of an image of given the number of histogram bins.
static std::string ImageOrientation(itk::SmartPointer< TImage > img)
Returns the orientation flag of an image.
static itk::SmartPointer< TImage > GaussianSmooth(itk::SmartPointer< TImage > img, const float variance)
Generates the Gaussian smoothing (by convolution) of an image using the variance provided.
static itk::SmartPointer< TImage > ImportMatrixToImage(vnl_matrix< TMatrix > &matrix, itk::SmartPointer< TImage > image=NULL)
Imports a VNL matrix to an ITK image object.
static itk::SmartPointer< TImage > ThresholdBelowImage(itk::SmartPointer< TImage > img, float outsideValue, float aboveValue)
Generates an image with the intensities below a certain level thresholded (capped) to the outsideValu...
static itk::SmartPointer< TImage > Laplacian(itk::SmartPointer< TImage > img)
Generates an Laplacian image from the input image.
static itk::SmartPointer< TImage > ResizeImage(itk::SmartPointer< TImage > img, typename TImage::SizeType imgSize)
Resizes current image using current spacing.
static itk::SmartPointer< TImage > MatchHistogram(itk::SmartPointer< TImage > img, itk::SmartPointer< TImage > imgToMatch, const int bins=128)
Changes the image gray levels to match histogram of image provided.
static itk::SmartPointer< TOutImage > DistanceMap(itk::SmartPointer< TImage > img, const bool binaryImage=false, const bool signedDistances=false, const bool computeInsideObject=false, const bool squaredDistance=false)
Generates a distance map image, where the distances are from the object boundary to the outside or vi...
static itk::SmartPointer< TOutImage > TransformImage(itk::SmartPointer< TImage > img, itk::SmartPointer< TOutImage > refImg, itk::SmartPointer< TTransform > transf, const bool inverse, const int interp=1)
Transform the image into a new reference image space given the transform.
static void ResampleCollection(std::vector< typename itk::SmartPointer< TImage > > &images, itk::SmartPointer< TRefImage > refImage)
Batch process images by resampling images using the reference image provided.
static double OtsuThreshold(itk::SmartPointer< TImage > img, const int bins)
Returns the Otsu threshold of an image of given the number of histogram bins.
static std::vector< typename itk::SmartPointer< TOutImage > > DistanceMapCollection(const std::vector< typename itk::SmartPointer< TImage > > &images, const bool binaryImage=false, const bool signedDistances=false, const bool computeInsideObject=false, const bool squaredDistance=false)
Batch process images by computing the distance map of each image. Output should always be a float ima...
static itk::SmartPointer< TImage > Bilateral(itk::SmartPointer< TImage > img, const float sigmaRange, const float sigmaSpatial)
Generates the (non-linear) Bilateral smoothing of an image using the sigmas provided.
static itk::SmartPointer< TImage > SobelEdges(itk::SmartPointer< TImage > img)
Generates an image with Sobel edges, i.e. uses the Sobel edge detection on the input image...
Represents an image (i.e. an regular rectangular array with scalar values) and their common operation...
static itk::SmartPointer< TImage > HistogramEqualisation(itk::SmartPointer< TImage > img, float alpha=0.3, float beta=0.3, float radius=5)
Generates an image with the intensities after histogram equalisation. Defaults to classic histogram e...
static itk::SmartPointer< TImage > DifferenceImages(itk::SmartPointer< TImage > img1, itk::SmartPointer< TImage > img2)
Same as SubtractImages().
static itk::SmartPointer< TOutImage > ResampleImage(itk::SmartPointer< TImage > img, itk::SmartPointer< TOutImage > refImg, const bool linearInterp=false)
Resample the image into a new reference image space given.
static std::vector< typename itk::SmartPointer< TOutImage > > BinaryThresholdCollection(const std::vector< typename itk::SmartPointer< TImage > > &images, float outsideValue, float insideValue, float belowValue, float aboveValue)
Batch process images by binary thresholding each image within band and inside value provided...
static vtkSmartPointer< vtkImageData > ApplyOrientationToVTKImage(vtkSmartPointer< vtkImageData > img, itk::SmartPointer< TImage > refImage, vtkSmartPointer< vtkMatrix4x4 > &transformMatrix, const bool labelledImage, const bool flipY=true)
Applies orientation/direction and origin to a VTK image from a reference image.
static void ThresholdBelowCollection(std::vector< typename itk::SmartPointer< TImage > > &images, float outsideValue, float belowValue)
Batch process images by thresholding each image from below.
static void InvertIntensityCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by inverting the intensities for each image.
itk::SmartPointer< TImage > Result()
Returns the current image, i.e. the result of the latest operation.
static itk::SmartPointer< TSubImage > ExtractSubImage(itk::SmartPointer< TImage > img, typename TImage::RegionType imgRegion)
Extract a sub image (such as a slice) from the current image given the region.
static itk::SmartPointer< TImage > AddCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by the adding the images together (pixel-wise).
void PrintInfo(const std::string msg)
Displays a generic msg to standard output with carriage return.
std::string NumberToString(double num, unsigned zeroPad=0)
Number to string converter.
itk::SmartPointer< TImage > PreviousResult()
Returns the previous image, i.e. the result of the penultimate operation.
static itk::SmartPointer< TImage > MatchInformation(itk::SmartPointer< TImage > img, itk::SmartPointer< TImage > imgToMatch, bool originOnly=false)
Changes the image info to match that of provided image. By default, only the spacing, region and origin are changed.
static itk::SmartPointer< TImage > MaskImage(itk::SmartPointer< TImage > img, itk::SmartPointer< TMaskImage > maskImg)
Mask an image by given binary image.
static itk::SmartPointer< TImage > AverageVectorCollection(std::vector< typename itk::SmartPointer< TImage > > &images, int numberOfComponents)
Batch process images by the averaging the vector images (pixel-wise).
static itk::SmartPointer< TImage > DifferenceCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Same as SubtractCollection.
static itk::SmartPointer< TImage > AddImages(itk::SmartPointer< TImage > img1, itk::SmartPointer< TImage > img2)
Adds image 1 to image 2, returning the result.
static void Information(itk::SmartPointer< TImage > img)
Prints the information of the image to standard output.
static itk::SmartPointer< TImage > FlipImage(itk::SmartPointer< TImage > img, bool xAxis=false, bool yAxis=true, bool zAxis=false, bool aboutOrigin=true)
Generates an image with axes flipped. Currently flips the y-axis as default, but can do other axes al...
static itk::SmartPointer< TImage > DuplicateImage(itk::SmartPointer< TImage > img)
Duplicates the image into a new image.
static void ResampleLabelCollection(std::vector< typename itk::SmartPointer< TImage > > &images, itk::SmartPointer< TRefImage > refImage)
Batch process labelled images by resampling images using the reference image provided. This uses the nearest neighbour interploator.
static void RelabelCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by relabelling unconnected regions consecutatively.
static itk::SmartPointer< TImage > ScaleVectorImage(itk::SmartPointer< TImage > img, float scaling, int numberOfComponents)
Scales each component of the vector image intensities by scaling factor and returns the result...
static itk::SmartPointer< TImage > CannyEdges(itk::SmartPointer< TImage > img, float variance, float lowerThreshold, float upperThreshold)
Generates an Canny edge image from the input image.
static itk::SmartPointer< itk::Image< float, TImage::ImageDimension > > Normalization(itk::SmartPointer< TImage > img)
Generates an image which is statistically normalised so having pixel values between -1 and 1...
static itk::SmartPointer< TImage > BlankImage(typename TImage::PixelType value, typename TImage::SizeType imgSize)
Creates an empty image filled with value given.
static std::vector< typename itk::SmartPointer< TOutImage > > CastCollection(const std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by casting each image to type provided in templates.
static void InformationCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by output the image information for each image.
static void GradientMagnitudeCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by hightlighting the edges of each image using Gradient magnitude information of...
static itk::SmartPointer< TImage > InvertIntensity(itk::SmartPointer< TImage > img, float maxValue)
Generates an image with the intensities reversed based on the max pixel value.
Applies a linear transformation to the magnitude of pixel vectors in a VectorImage.
static itk::SmartPointer< TOutImage > AverageCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by the averaging the images (pixel-wise).
static itk::SmartPointer< TImage > Median(itk::SmartPointer< TImage > img, const int radius)
Generates the (non-linear) median filtering (smoothing) of an image of given neighbourhood radius...
static std::vector< typename itk::SmartPointer< TOutImage > > OtsuMultipleThresholdCollection(const std::vector< typename itk::SmartPointer< TImage > > &images, const int bins, const int noOfLabels)
Batch process images by Otsu (histogram-based) thresholding each image having number of partitions/la...
static itk::SmartPointer< TImage > PadImageByConstant(itk::SmartPointer< TImage > img, size_t xAxis, size_t yAxis, size_t zAxis, typename TImage::PixelType value)
Generates an image padded by extending each axes by size given in both directions. The created areas have the value given by value.
itk::SmartPointer< TImage > GetOutput()
Returns the current image, i.e. the result of the latest operation ITK/VTK style. ...
static void LaplacianCollection(std::vector< typename itk::SmartPointer< TImage > > &images)
Batch process images by hightlighting the edges of each image using the Laplacian of the image...
static itk::SmartPointer< TImageComponent > ExtractComponent(itk::SmartPointer< TImage > img, int component)
Extract a component from the current vector image given the component index.
static itk::SmartPointer< TImage > SubsampleImage(itk::SmartPointer< TImage > img, typename TImage::SizeType factors)
Subsamples or shrinks the current image using the factors provided.
static void CheckerboardCollection(std::vector< typename itk::SmartPointer< TImage > > &images, itk::SmartPointer< TImage > refImage, const int squares=10)
Batch process images by checkerboarding all of the images to the reference image provided.
static void MatchHistogramCollection(std::vector< typename itk::SmartPointer< TImage > > &images, itk::SmartPointer< TImage > refImage, const int bins=128)
Batch process images by matching the histograms of the images to the reference image provided...
static void MaskCollection(std::vector< typename itk::SmartPointer< TImage > > &images, itk::SmartPointer< TMaskImage > maskImage)
Batch process images by masking using the mask image provided.