diff --git a/src/Filtering/AnisotropicSmoothing/ComputeCurvatureAnisotropicDiffusion/Code.cxx b/src/Filtering/AnisotropicSmoothing/ComputeCurvatureAnisotropicDiffusion/Code.cxx index 5d0a9dbe1..cf490f6f6 100644 --- a/src/Filtering/AnisotropicSmoothing/ComputeCurvatureAnisotropicDiffusion/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/ComputeCurvatureAnisotropicDiffusion/Code.cxx @@ -48,13 +48,11 @@ main(int argc, char * argv[]) const InputPixelType timeStep = std::stod(argv[4]); const InputPixelType conductance = std::stod(argv[5]); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::CurvatureAnisotropicDiffusionImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetNumberOfIterations(numberOfIterations); filter->SetTimeStep(timeStep); filter->SetConductanceParameter(conductance); @@ -65,14 +63,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(itk::NumericTraits::min()); rescaler->SetOutputMaximum(itk::NumericTraits::max()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/AnisotropicSmoothing/ComputeCurvatureFlow/Code.cxx b/src/Filtering/AnisotropicSmoothing/ComputeCurvatureFlow/Code.cxx index 754f70255..3d1662faa 100644 --- a/src/Filtering/AnisotropicSmoothing/ComputeCurvatureFlow/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/ComputeCurvatureFlow/Code.cxx @@ -47,13 +47,11 @@ main(int argc, char * argv[]) const int numberOfIterations = std::stoi(argv[3]); const InputPixelType timeStep = std::stod(argv[4]); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::CurvatureFlowImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetNumberOfIterations(numberOfIterations); filter->SetTimeStep(timeStep); @@ -63,14 +61,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(itk::NumericTraits::min()); rescaler->SetOutputMaximum(itk::NumericTraits::max()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/AnisotropicSmoothing/ComputeGradientAnisotropicDiffusion/Code.cxx b/src/Filtering/AnisotropicSmoothing/ComputeGradientAnisotropicDiffusion/Code.cxx index 1740b0b99..e8b067a13 100644 --- a/src/Filtering/AnisotropicSmoothing/ComputeGradientAnisotropicDiffusion/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/ComputeGradientAnisotropicDiffusion/Code.cxx @@ -48,13 +48,11 @@ main(int argc, char * argv[]) const InputPixelType timeStep = std::stod(argv[4]); const InputPixelType conductance = std::stod(argv[5]); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::GradientAnisotropicDiffusionImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetNumberOfIterations(numberOfIterations); filter->SetTimeStep(timeStep); filter->SetConductanceParameter(conductance); @@ -65,14 +63,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(itk::NumericTraits::min()); rescaler->SetOutputMaximum(itk::NumericTraits::max()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/AnisotropicSmoothing/ComputePeronaMalikAnisotropicDiffusion/Code.cxx b/src/Filtering/AnisotropicSmoothing/ComputePeronaMalikAnisotropicDiffusion/Code.cxx index 8e567f8fa..bc2eb57b0 100644 --- a/src/Filtering/AnisotropicSmoothing/ComputePeronaMalikAnisotropicDiffusion/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/ComputePeronaMalikAnisotropicDiffusion/Code.cxx @@ -40,27 +40,20 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using OutputPixelType = float; using OutputImageType = itk::Image; using FilterType = itk::GradientAnisotropicDiffusionImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetNumberOfIterations(std::stoi(argv[3])); filter->SetTimeStep(0.125); filter->SetConductanceParameter(std::stod(argv[4])); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges/Code.cxx b/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges/Code.cxx index 6d41b9cda..a67fb70c7 100644 --- a/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges/Code.cxx @@ -51,14 +51,12 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image, 2>; // 1) Read the RGB image - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // 2) Cast to Vector image for processing using AdaptorInputType = itk::RGBToVectorImageAdaptor; AdaptorInputType::Pointer adaptInput = AdaptorInputType::New(); - adaptInput->SetImage(reader->GetOutput()); + adaptInput->SetImage(input); using CastInputType = itk::CastImageFilter; CastInputType::Pointer castInput = CastInputType::New(); castInput->SetInput(adaptInput); @@ -90,7 +88,7 @@ main(int argc, char * argv[]) // 5) Display the input and smoothed images #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddRGBImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFileName)); + viewer.AddRGBImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "VectorGradientAnisotropicDiffusionImageFilter\niterations: " << filter->GetNumberOfIterations() diff --git a/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges2/Code.cxx b/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges2/Code.cxx index 298bafbd7..5e09bfba5 100644 --- a/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges2/Code.cxx +++ b/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges2/Code.cxx @@ -50,14 +50,12 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image, 2>; // 1) Read the RGB image - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // 2) Cast to Vector image for processing using AdaptorInputType = itk::RGBToVectorImageAdaptor; AdaptorInputType::Pointer adaptInput = AdaptorInputType::New(); - adaptInput->SetImage(reader->GetOutput()); + adaptInput->SetImage(input); using CastInputType = itk::CastImageFilter; CastInputType::Pointer castInput = CastInputType::New(); castInput->SetInput(adaptInput); @@ -89,7 +87,7 @@ main(int argc, char * argv[]) // 5) Display the input and smoothed images #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddRGBImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFileName)); + viewer.AddRGBImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "VectorCurvatureAnisotropicDiffusionImageFilter\niterations: " << filter->GetNumberOfIterations() diff --git a/src/Filtering/AntiAlias/SmoothBinaryImageBeforeSurfaceExtraction/Code.cxx b/src/Filtering/AntiAlias/SmoothBinaryImageBeforeSurfaceExtraction/Code.cxx index 8311d697a..577d2c670 100644 --- a/src/Filtering/AntiAlias/SmoothBinaryImageBeforeSurfaceExtraction/Code.cxx +++ b/src/Filtering/AntiAlias/SmoothBinaryImageBeforeSurfaceExtraction/Code.cxx @@ -52,29 +52,21 @@ main(int argc, char * argv[]) } constexpr unsigned int Dimension = 2; - using PixelType = float; - using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::AntiAliasBinaryImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetMaximumRMSError(maximumRMSError); filter->SetNumberOfIterations(numberOfIterations); filter->SetNumberOfLayers(numberOfLayers); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx index 2d61f0887..6c4758fd7 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ClosingBinaryImage/Code.cxx @@ -45,11 +45,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } unsigned int radius = 5; diff --git a/src/Filtering/BinaryMathematicalMorphology/DilateABinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/DilateABinaryImage/Code.cxx index 892ec4322..428d2c9d7 100644 --- a/src/Filtering/BinaryMathematicalMorphology/DilateABinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/DilateABinaryImage/Code.cxx @@ -38,11 +38,9 @@ main(int argc, char * argv[]) using PixelType = unsigned char; constexpr unsigned int Dimension = 2; - using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + + const auto input = itk::ReadImage(inputImage); using StructuringElementType = itk::FlatStructuringElement; StructuringElementType::RadiusType radius; @@ -52,18 +50,13 @@ main(int argc, char * argv[]) using BinaryDilateImageFilterType = itk::BinaryDilateImageFilter; BinaryDilateImageFilterType::Pointer dilateFilter = BinaryDilateImageFilterType::New(); - dilateFilter->SetInput(reader->GetOutput()); + dilateFilter->SetInput(input); dilateFilter->SetKernel(structuringElement); dilateFilter->SetForegroundValue(255); // Value to dilate - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(dilateFilter->GetOutput()); - writer->SetFileName(outputImage); - try { - writer->Update(); + itk::WriteImage(dilateFilter->GetOutput(), outputImage); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/BinaryMathematicalMorphology/ErodeABinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ErodeABinaryImage/Code.cxx index 819f3a5ce..292c09df9 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ErodeABinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ErodeABinaryImage/Code.cxx @@ -38,11 +38,9 @@ main(int argc, char * argv[]) using PixelType = unsigned char; constexpr unsigned int Dimension = 2; - using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + + const auto input = itk::ReadImage(inputImage); using StructuringElementType = itk::FlatStructuringElement; StructuringElementType::RadiusType radius; @@ -52,19 +50,14 @@ main(int argc, char * argv[]) using BinaryErodeImageFilterType = itk::BinaryErodeImageFilter; BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); - erodeFilter->SetInput(reader->GetOutput()); + erodeFilter->SetInput(input); erodeFilter->SetKernel(structuringElement); erodeFilter->SetForegroundValue(255); // Intensity value to erode erodeFilter->SetBackgroundValue(0); // Replacement value for eroded voxels - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(erodeFilter->GetOutput()); - writer->SetFileName(outputImage); - try { - writer->Update(); + itk::WriteImage(erodeFilter->GetOutput(), outputImage); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx index 2654ae3a8..f944340fe 100644 --- a/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/OpeningBinaryImage/Code.cxx @@ -45,11 +45,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } unsigned int radius = 5; diff --git a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx index 2f93c9f48..431109de9 100644 --- a/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/PruneBinaryImage/Code.cxx @@ -19,7 +19,6 @@ #include "itkBinaryPruningImageFilter.h" #include "itkImageFileReader.h" #include "itkBinaryBallStructuringElement.h" -#include "itkImageFileWriter.h" #ifdef ENABLE_QUICKVIEW # include "QuickView.h" @@ -47,10 +46,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); std::stringstream ssIteration(argv[2]); } diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx index 255dac42f..b20e5eae2 100644 --- a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx +++ b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx @@ -23,8 +23,6 @@ using ImageType = itk::Image; -static void -WriteImage(const ImageType::Pointer image, const std::string & fileName); static void CreateImage(ImageType::Pointer image); @@ -34,17 +32,12 @@ main(int argc, char * argv[]) ImageType::Pointer image = ImageType::New(); if (argc == 2) { - using ImageReader = itk::ImageFileReader; - ImageReader::Pointer reader = ImageReader::New(); - std::string fileName = argv[1]; - reader->SetFileName(fileName); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } else { CreateImage(image); - WriteImage(image, "input.png"); + itk::WriteImage(image, "input.png"); } using BinaryThinningImageFilterType = itk::BinaryThinningImageFilter; @@ -60,7 +53,7 @@ main(int argc, char * argv[]) rescaler->SetOutputMaximum(255); rescaler->Update(); - WriteImage(rescaler->GetOutput(), "output.png"); + itk::WriteImage(rescaler->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -93,13 +86,3 @@ CreateImage(ImageType::Pointer image) } } } - -void -WriteImage(const ImageType::Pointer image, const std::string & fileName) -{ - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(fileName); - writer->SetInput(image); - writer->Update(); -} diff --git a/src/Filtering/Colormap/ApplyAColormapToAnImage/Code.cxx b/src/Filtering/Colormap/ApplyAColormapToAnImage/Code.cxx index bf75e4283..fed9555bb 100644 --- a/src/Filtering/Colormap/ApplyAColormapToAnImage/Code.cxx +++ b/src/Filtering/Colormap/ApplyAColormapToAnImage/Code.cxx @@ -40,26 +40,19 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using RGBPixelType = itk::RGBPixel; using RGBImageType = itk::Image; using RGBFilterType = itk::ScalarToRGBColormapImageFilter; RGBFilterType::Pointer rgbfilter = RGBFilterType::New(); - rgbfilter->SetInput(reader->GetOutput()); + rgbfilter->SetInput(input); rgbfilter->SetColormap(itk::ScalarToRGBColormapImageFilterEnums::RGBColormapFilter::Hot); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(rgbfilter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rgbfilter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Colormap/CreateACustomColormap/Code.cxx b/src/Filtering/Colormap/CreateACustomColormap/Code.cxx index 79b3e4570..2786feaca 100644 --- a/src/Filtering/Colormap/CreateACustomColormap/Code.cxx +++ b/src/Filtering/Colormap/CreateACustomColormap/Code.cxx @@ -45,10 +45,7 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; using ImageType = itk::Image; - - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using ColormapType = itk::Function::CustomColormapFunction; ColormapType::Pointer colormap = ColormapType::New(); @@ -78,17 +75,12 @@ main(int argc, char * argv[]) using ColormapFilterType = itk::ScalarToRGBColormapImageFilter; ColormapFilterType::Pointer colormapFilter1 = ColormapFilterType::New(); - colormapFilter1->SetInput(reader->GetOutput()); + colormapFilter1->SetInput(input); colormapFilter1->SetColormap(colormap); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(colormapFilter1->GetOutput()); - writer->SetFileName(argv[2]); - try { - writer->Update(); + itk::WriteImage(colormapFilter1->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Convolution/ColorNormalizedCorrelation/Code.cxx b/src/Filtering/Convolution/ColorNormalizedCorrelation/Code.cxx index 9882beda1..2ee380448 100644 --- a/src/Filtering/Convolution/ColorNormalizedCorrelation/Code.cxx +++ b/src/Filtering/Convolution/ColorNormalizedCorrelation/Code.cxx @@ -53,14 +53,7 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - std::string filename = argv[1]; - - using ReaderType = itk::ImageFileReader; - - // Read the image - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(filename.c_str()); - reader->Update(); + const auto input = itk::ReadImage(argv[1]); // Extract a small region using ExtractFilterType = itk::RegionOfInterestImageFilter; @@ -76,7 +69,7 @@ main(int argc, char * argv[]) FloatImageType::RegionType desiredRegion(start, patchSize); extractFilter->SetRegionOfInterest(desiredRegion); - extractFilter->SetInput(reader->GetOutput()); + extractFilter->SetInput(input); extractFilter->Update(); // Perform normalized correlation @@ -95,7 +88,7 @@ main(int argc, char * argv[]) kernelOperator.CreateToRadius(radius); CorrelationFilterType::Pointer correlationFilter = CorrelationFilterType::New(); - correlationFilter->SetInput(reader->GetOutput()); + correlationFilter->SetInput(input); correlationFilter->SetTemplate(kernelOperator); correlationFilter->Update(); @@ -113,7 +106,6 @@ main(int argc, char * argv[]) // (50,50) using RescaleFilterType = itk::RescaleIntensityImageFilter; - using WriterType = itk::ImageFileWriter; { RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); rescaleFilter->SetInput(correlationFilter->GetOutput()); @@ -121,10 +113,7 @@ main(int argc, char * argv[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaleFilter->GetOutput()); - writer->SetFileName("correlation.png"); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png"); } { @@ -134,10 +123,7 @@ main(int argc, char * argv[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaleFilter->GetOutput()); - writer->SetFileName("patch.png"); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "patch.png"); } // Extract the best matching patch @@ -149,12 +135,12 @@ main(int argc, char * argv[]) ExtractFilterType::Pointer bestPatchExtractFilter = ExtractFilterType::New(); bestPatchExtractFilter->SetRegionOfInterest(bestPatchRegion); - bestPatchExtractFilter->SetInput(reader->GetOutput()); + bestPatchExtractFilter->SetInput(input); bestPatchExtractFilter->Update(); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(extractFilter->GetOutput()); viewer.AddImage(correlationFilter->GetOutput()); viewer.AddImage(bestPatchExtractFilter->GetOutput()); diff --git a/src/Filtering/Convolution/ConvolveImageWithKernel/Code.cxx b/src/Filtering/Convolution/ConvolveImageWithKernel/Code.cxx index 2b4f52c90..641035bc4 100644 --- a/src/Filtering/Convolution/ConvolveImageWithKernel/Code.cxx +++ b/src/Filtering/Convolution/ConvolveImageWithKernel/Code.cxx @@ -50,16 +50,12 @@ main(int argc, char * argv[]) ImageType::Pointer kernel = ImageType::New(); CreateKernel(kernel, width); - using ReaderType = itk::ImageFileReader; - using FilterType = itk::ConvolutionImageFilter; - - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); // Convolve image with kernel. + using FilterType = itk::ConvolutionImageFilter; FilterType::Pointer convolutionFilter = FilterType::New(); - convolutionFilter->SetInput(reader->GetOutput()); + convolutionFilter->SetInput(input); #if ITK_VERSION_MAJOR >= 4 convolutionFilter->SetKernelImage(kernel); #else @@ -67,7 +63,7 @@ main(int argc, char * argv[]) #endif #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); std::stringstream desc; desc << "ConvolutionFilter\n" diff --git a/src/Filtering/Convolution/NormalizedCorrelation/Code.cxx b/src/Filtering/Convolution/NormalizedCorrelation/Code.cxx index 4bf482606..58276ec1f 100644 --- a/src/Filtering/Convolution/NormalizedCorrelation/Code.cxx +++ b/src/Filtering/Convolution/NormalizedCorrelation/Code.cxx @@ -42,14 +42,7 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - std::string filename = argv[1]; - - using ReaderType = itk::ImageFileReader; - - // Read the image - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(filename.c_str()); - reader->Update(); + const auto input = itk::ReadImage(argv[1]); // Extract a small region using ExtractFilterType = itk::RegionOfInterestImageFilter; @@ -65,7 +58,7 @@ main(int argc, char * argv[]) FloatImageType::RegionType desiredRegion(start, patchSize); extractFilter->SetRegionOfInterest(desiredRegion); - extractFilter->SetInput(reader->GetOutput()); + extractFilter->SetInput(input); extractFilter->Update(); // Perform normalized correlation @@ -83,7 +76,7 @@ main(int argc, char * argv[]) kernelOperator.CreateToRadius(radius); CorrelationFilterType::Pointer correlationFilter = CorrelationFilterType::New(); - correlationFilter->SetInput(reader->GetOutput()); + correlationFilter->SetInput(input); correlationFilter->SetTemplate(kernelOperator); correlationFilter->Update(); @@ -101,7 +94,6 @@ main(int argc, char * argv[]) // (50,50) using RescaleFilterType = itk::RescaleIntensityImageFilter; - using WriterType = itk::ImageFileWriter; { RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); rescaleFilter->SetInput(correlationFilter->GetOutput()); @@ -109,10 +101,7 @@ main(int argc, char * argv[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaleFilter->GetOutput()); - writer->SetFileName("correlation.png"); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png"); } { @@ -122,10 +111,7 @@ main(int argc, char * argv[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaleFilter->GetOutput()); - writer->SetFileName("patch.png"); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "patch.png"); } // Extract the best matching patch @@ -137,12 +123,12 @@ main(int argc, char * argv[]) ExtractFilterType::Pointer bestPatchExtractFilter = ExtractFilterType::New(); bestPatchExtractFilter->SetRegionOfInterest(bestPatchRegion); - bestPatchExtractFilter->SetInput(reader->GetOutput()); + bestPatchExtractFilter->SetInput(input); bestPatchExtractFilter->Update(); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(extractFilter->GetOutput()); viewer.AddImage(correlationFilter->GetOutput()); viewer.AddImage(bestPatchExtractFilter->GetOutput()); diff --git a/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx b/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx index 72efcfcd6..d4d1dc8d4 100644 --- a/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx +++ b/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx @@ -18,7 +18,6 @@ // Maximum value is inf?? #include "itkImage.h" -#include "itkImageFileReader.h" #include "itkNormalizedCorrelationImageFilter.h" #include "itkRegionOfInterestImageFilter.h" #include "itkImageKernelOperator.h" @@ -40,10 +39,6 @@ CreateImage(ImageType * const image); void CreateImageOfSquare(ImageType * const image, const itk::Index<2> & cornerOfSquare); -template -void -WriteImage(const TImage * const image, const std::string & filename); - int main(int, char *[]) { @@ -51,7 +46,7 @@ main(int, char *[]) MaskType::Pointer mask = MaskType::New(); CreateMask(mask); - WriteImage(mask.GetPointer(), "mask.png"); + itk::WriteImage(mask.GetPointer(), "mask.png"); // Setup image1 ImageType::Pointer image1 = ImageType::New(); @@ -59,7 +54,7 @@ main(int, char *[]) cornerOfSquare1[0] = 3; cornerOfSquare1[1] = 8; CreateImageOfSquare(image1, cornerOfSquare1); - WriteImage(image1.GetPointer(), "image1.png"); + itk::WriteImage(image1.GetPointer(), "image1.png"); // Setup image2 itk::Index<2> offset; @@ -72,7 +67,7 @@ main(int, char *[]) cornerOfSquare2[1] = cornerOfSquare1[1] + offset[1]; CreateImageOfSquare(image2, cornerOfSquare2); - WriteImage(image2.GetPointer(), "image2.png"); + itk::WriteImage(image2.GetPointer(), "image2.png"); // Create a kernel from an image itk::ImageKernelOperator kernelOperator; @@ -101,7 +96,7 @@ main(int, char *[]) correlationFilter->SetTemplate(kernelOperator); correlationFilter->Update(); - WriteImage(correlationFilter->GetOutput(), "correlation.mha"); + itk::WriteImage(correlationFilter->GetOutput(), "correlation.mha"); using RescaleFilterType = itk::RescaleIntensityImageFilter; RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); @@ -109,7 +104,7 @@ main(int, char *[]) rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriteImage(rescaleFilter->GetOutput(), "correlation.png"); + itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png"); using MinimumMaximumImageCalculatorType = itk::MinimumMaximumImageCalculator; MinimumMaximumImageCalculatorType::Pointer minimumMaximumImageCalculatorFilter = @@ -210,14 +205,3 @@ CreateImageOfSquare(ImageType * const image, const itk::Index<2> & cornerOfSquar ++imageIterator; } } - -template -void -WriteImage(const TImage * const image, const std::string & filename) -{ - using WriterType = itk::ImageFileWriter; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(filename); - writer->SetInput(image); - writer->Update(); -} diff --git a/src/Filtering/Convolution/NormalizedCorrelationUsingFFT/Code.cxx b/src/Filtering/Convolution/NormalizedCorrelationUsingFFT/Code.cxx index 82bf20ad8..127983313 100644 --- a/src/Filtering/Convolution/NormalizedCorrelationUsingFFT/Code.cxx +++ b/src/Filtering/Convolution/NormalizedCorrelationUsingFFT/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileReader.h" #include "itkFFTNormalizedCorrelationImageFilter.h" #include "itkRegionOfInterestImageFilter.h" #include "itkImageKernelOperator.h" @@ -38,10 +37,6 @@ using FloatImageType = itk::Image; static void CreateImage(ImageType::Pointer image, const itk::Index<2> & cornerOfSquare); -template -static void -WriteImage(TImage * const image, const std::string & filename); - int main(int, char *[]) { @@ -54,14 +49,14 @@ main(int, char *[]) cornerOfFixedSquare[0] = 3; cornerOfFixedSquare[1] = 8; CreateImage(fixedImage, cornerOfFixedSquare); - WriteImage(fixedImage.GetPointer(), "fixedImage.png"); + itk::WriteImage(fixedImage.GetPointer(), "fixedImage.png"); ImageType::Pointer movingImage = ImageType::New(); itk::Index<2> cornerOfMovingSquare; cornerOfMovingSquare[0] = cornerOfFixedSquare[0] + offset[0]; cornerOfMovingSquare[1] = cornerOfFixedSquare[1] + offset[1]; CreateImage(movingImage, cornerOfMovingSquare); - WriteImage(movingImage.GetPointer(), "movingImage.png"); + itk::WriteImage(movingImage.GetPointer(), "movingImage.png"); // Perform normalized correlation using CorrelationFilterType = itk::FFTNormalizedCorrelationImageFilter; @@ -70,7 +65,7 @@ main(int, char *[]) correlationFilter->SetMovingImage(movingImage); correlationFilter->Update(); - WriteImage(correlationFilter->GetOutput(), "correlation.mha"); + itk::WriteImage(correlationFilter->GetOutput(), "correlation.mha"); using RescaleFilterType = itk::RescaleIntensityImageFilter; RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); @@ -78,7 +73,7 @@ main(int, char *[]) rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriteImage(rescaleFilter->GetOutput(), "correlation.png"); + itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png"); using MinimumMaximumImageCalculatorType = itk::MinimumMaximumImageCalculator; MinimumMaximumImageCalculatorType::Pointer minimumMaximumImageCalculatorFilter = @@ -134,14 +129,3 @@ CreateImage(ImageType::Pointer image, const itk::Index<2> & cornerOfSquare) ++imageIterator; } } - -template -void -WriteImage(TImage * const image, const std::string & filename) -{ - using WriterType = itk::ImageFileWriter; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(filename); - writer->SetInput(image); - writer->Update(); -} diff --git a/src/Filtering/Convolution/NormalizedCorrelationUsingFFTWithMaskImages/Code.cxx b/src/Filtering/Convolution/NormalizedCorrelationUsingFFTWithMaskImages/Code.cxx index 640a6aa0b..a86c40205 100644 --- a/src/Filtering/Convolution/NormalizedCorrelationUsingFFTWithMaskImages/Code.cxx +++ b/src/Filtering/Convolution/NormalizedCorrelationUsingFFTWithMaskImages/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileReader.h" #include "itkFFTNormalizedCorrelationImageFilter.h" #include "itkRegionOfInterestImageFilter.h" #include "itkImageKernelOperator.h" @@ -39,10 +38,6 @@ CreateMask(MaskType * const mask); static void CreateImage(ImageType::Pointer image, const itk::Index<2> & cornerOfSquare); -template -void -WriteImage(TImage * const image, const std::string & filename); - int main(int, char *[]) { @@ -59,14 +54,14 @@ main(int, char *[]) cornerOfFixedSquare[0] = 3; cornerOfFixedSquare[1] = 8; CreateImage(fixedImage, cornerOfFixedSquare); - WriteImage(fixedImage.GetPointer(), "fixedImage.png"); + itk::WriteImage(fixedImage.GetPointer(), "fixedImage.png"); ImageType::Pointer movingImage = ImageType::New(); itk::Index<2> cornerOfMovingSquare; cornerOfMovingSquare[0] = cornerOfFixedSquare[0] + offset[0]; cornerOfMovingSquare[1] = cornerOfFixedSquare[1] + offset[1]; CreateImage(movingImage, cornerOfMovingSquare); - WriteImage(movingImage.GetPointer(), "movingImage.png"); + itk::WriteImage(movingImage.GetPointer(), "movingImage.png"); // Perform normalized correlation using CorrelationFilterType = itk::FFTNormalizedCorrelationImageFilter; @@ -77,7 +72,7 @@ main(int, char *[]) // correlationFilter->SetFixedImageMask(mask); correlationFilter->Update(); - WriteImage(correlationFilter->GetOutput(), "correlation.mha"); + itk::WriteImage(correlationFilter->GetOutput(), "correlation.mha"); using RescaleFilterType = itk::RescaleIntensityImageFilter; RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); @@ -85,7 +80,7 @@ main(int, char *[]) rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - WriteImage(rescaleFilter->GetOutput(), "correlation.png"); + itk::WriteImage(rescaleFilter->GetOutput(), "correlation.png"); using MinimumMaximumImageCalculatorType = itk::MinimumMaximumImageCalculator; MinimumMaximumImageCalculatorType::Pointer minimumMaximumImageCalculatorFilter = @@ -142,18 +137,6 @@ CreateImage(ImageType::Pointer image, const itk::Index<2> & cornerOfSquare) } } -template -void -WriteImage(TImage * const image, const std::string & filename) -{ - using WriterType = itk::ImageFileWriter; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(filename); - writer->SetInput(image); - writer->Update(); -} - - void CreateMask(MaskType * const mask) { diff --git a/src/Filtering/CurvatureFlow/BinaryMinMaxCurvatureFlow/Code.cxx b/src/Filtering/CurvatureFlow/BinaryMinMaxCurvatureFlow/Code.cxx index 7f89be3b9..d76f727cf 100644 --- a/src/Filtering/CurvatureFlow/BinaryMinMaxCurvatureFlow/Code.cxx +++ b/src/Filtering/CurvatureFlow/BinaryMinMaxCurvatureFlow/Code.cxx @@ -47,29 +47,25 @@ main(int argc, char * argv[]) using InputPixelType = float; using OutputPixelType = float; - using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - using OutputImageType = itk::Image; + const auto input = itk::ReadImage(inputFileName); + using FilterType = itk::BinaryMinMaxCurvatureFlowImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetThreshold(255); filter->SetNumberOfIterations(numberOfIterations); using SubtractType = itk::SubtractImageFilter; SubtractType::Pointer diff = SubtractType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(filter->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFileName)); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "BinaryMinMaxCurvature, iterations = " << numberOfIterations; diff --git a/src/Filtering/CurvatureFlow/SmoothImageUsingCurvatureFlow/Code.cxx b/src/Filtering/CurvatureFlow/SmoothImageUsingCurvatureFlow/Code.cxx index d5533ab72..2713cbfbc 100644 --- a/src/Filtering/CurvatureFlow/SmoothImageUsingCurvatureFlow/Code.cxx +++ b/src/Filtering/CurvatureFlow/SmoothImageUsingCurvatureFlow/Code.cxx @@ -45,28 +45,24 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using InternalImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - - ReaderType::Pointer reader = ReaderType::New(); - - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using CurvatureFlowImageFilterType = itk::CurvatureFlowImageFilter; CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New(); - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); smoothing->SetNumberOfIterations(iterations); smoothing->SetTimeStep(0.125); using SubtractImageFilterType = itk::SubtractImageFilter; SubtractImageFilterType::Pointer diff = SubtractImageFilterType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(smoothing->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); std::stringstream desc; desc << "CurvatureFlow\niterations = " << iterations; diff --git a/src/Filtering/CurvatureFlow/SmoothImageUsingMinMaxCurvatureFlow/Code.cxx b/src/Filtering/CurvatureFlow/SmoothImageUsingMinMaxCurvatureFlow/Code.cxx index 3804249c7..396b7650f 100644 --- a/src/Filtering/CurvatureFlow/SmoothImageUsingMinMaxCurvatureFlow/Code.cxx +++ b/src/Filtering/CurvatureFlow/SmoothImageUsingMinMaxCurvatureFlow/Code.cxx @@ -20,7 +20,6 @@ #include "itkMinMaxCurvatureFlowImageFilter.h" #include "itkSubtractImageFilter.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #ifdef ENABLE_QUICKVIEW # include "QuickView.h" @@ -44,32 +43,29 @@ main(int argc, char * argv[]) std::stringstream ss(argv[2]); ss >> iterations; } - std::string inputFilename = argv[1]; using PixelType = float; constexpr unsigned int Dimension = 2; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; using MinMaxCurvatureFlowImageFilterType = itk::MinMaxCurvatureFlowImageFilter; using SubtractType = itk::SubtractImageFilter; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); + const auto input = itk::ReadImage(inputFileName); MinMaxCurvatureFlowImageFilterType::Pointer minMaxCurvatureFlowImageFilter = MinMaxCurvatureFlowImageFilterType::New(); - minMaxCurvatureFlowImageFilter->SetInput(reader->GetOutput()); + minMaxCurvatureFlowImageFilter->SetInput(input); minMaxCurvatureFlowImageFilter->SetNumberOfIterations(iterations); minMaxCurvatureFlowImageFilter->SetTimeStep(0.125); SubtractType::Pointer diff = SubtractType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(minMaxCurvatureFlowImageFilter->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename)); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "MinMaxCurvatureFlow, iterations = " << iterations; diff --git a/src/Filtering/CurvatureFlow/SmoothRGBImageUsingCurvatureFlow/Code.cxx b/src/Filtering/CurvatureFlow/SmoothRGBImageUsingCurvatureFlow/Code.cxx index 82da778aa..5ba2f05bd 100644 --- a/src/Filtering/CurvatureFlow/SmoothRGBImageUsingCurvatureFlow/Code.cxx +++ b/src/Filtering/CurvatureFlow/SmoothRGBImageUsingCurvatureFlow/Code.cxx @@ -47,27 +47,23 @@ main(int argc, char * argv[]) std::stringstream ss(argv[2]); ss >> iterations; } - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using ComponentType = float; using PixelType = itk::RGBPixel; using RGBImageType = itk::Image; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; using ImageAdaptorType = itk::NthElementImageAdaptor; using ComposeType = itk::ComposeImageFilter; using CurvatureFlowType = itk::CurvatureFlowImageFilter; - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); - reader->Update(); + const auto input = itk::ReadImage(inputFileName); // Run the filter for each component ImageAdaptorType::Pointer rAdaptor = ImageAdaptorType::New(); rAdaptor->SelectNthElement(0); - rAdaptor->SetImage(reader->GetOutput()); + rAdaptor->SetImage(input); CurvatureFlowType::Pointer rCurvatureFilter = CurvatureFlowType::New(); rCurvatureFilter->SetInput(rAdaptor); @@ -76,7 +72,7 @@ main(int argc, char * argv[]) ImageAdaptorType::Pointer gAdaptor = ImageAdaptorType::New(); gAdaptor->SelectNthElement(1); - gAdaptor->SetImage(reader->GetOutput()); + gAdaptor->SetImage(input); CurvatureFlowType::Pointer gCurvatureFilter = CurvatureFlowType::New(); gCurvatureFilter->SetInput(gAdaptor); @@ -85,7 +81,7 @@ main(int argc, char * argv[]) ImageAdaptorType::Pointer bAdaptor = ImageAdaptorType::New(); bAdaptor->SelectNthElement(2); - bAdaptor->SetImage(reader->GetOutput()); + bAdaptor->SetImage(input); CurvatureFlowType::Pointer bCurvatureFilter = CurvatureFlowType::New(); bCurvatureFilter->SetInput(bAdaptor); @@ -101,7 +97,7 @@ main(int argc, char * argv[]) #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddRGBImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename)); + viewer.AddRGBImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "CurvatureFlow iterations = " << iterations; diff --git a/src/Filtering/CurvatureFlow/SmoothRGBImageUsingMinMaxCurvatureFlow/Code.cxx b/src/Filtering/CurvatureFlow/SmoothRGBImageUsingMinMaxCurvatureFlow/Code.cxx index ece387f83..96a099c12 100644 --- a/src/Filtering/CurvatureFlow/SmoothRGBImageUsingMinMaxCurvatureFlow/Code.cxx +++ b/src/Filtering/CurvatureFlow/SmoothRGBImageUsingMinMaxCurvatureFlow/Code.cxx @@ -47,27 +47,23 @@ main(int argc, char * argv[]) std::stringstream ss(argv[2]); ss >> iterations; } - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using ComponentType = float; using PixelType = itk::RGBPixel; using RGBImageType = itk::Image; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; using ImageAdaptorType = itk::NthElementImageAdaptor; using ComposeType = itk::ComposeImageFilter; using CurvatureFlowType = itk::MinMaxCurvatureFlowImageFilter; - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); - reader->Update(); + const auto input = itk::ReadImage(inputFileName); // Run the filter for each component ImageAdaptorType::Pointer rAdaptor = ImageAdaptorType::New(); rAdaptor->SelectNthElement(0); - rAdaptor->SetImage(reader->GetOutput()); + rAdaptor->SetImage(input); CurvatureFlowType::Pointer rCurvatureFilter = CurvatureFlowType::New(); rCurvatureFilter->SetInput(rAdaptor); @@ -76,7 +72,7 @@ main(int argc, char * argv[]) ImageAdaptorType::Pointer gAdaptor = ImageAdaptorType::New(); gAdaptor->SelectNthElement(1); - gAdaptor->SetImage(reader->GetOutput()); + gAdaptor->SetImage(input); CurvatureFlowType::Pointer gCurvatureFilter = CurvatureFlowType::New(); gCurvatureFilter->SetInput(gAdaptor); @@ -85,7 +81,7 @@ main(int argc, char * argv[]) ImageAdaptorType::Pointer bAdaptor = ImageAdaptorType::New(); bAdaptor->SelectNthElement(2); - bAdaptor->SetImage(reader->GetOutput()); + bAdaptor->SetImage(input); CurvatureFlowType::Pointer bCurvatureFilter = CurvatureFlowType::New(); bCurvatureFilter->SetInput(bAdaptor); @@ -101,7 +97,7 @@ main(int argc, char * argv[]) #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddRGBImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename)); + viewer.AddRGBImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "MinMaxCurvatureFlow iterations = " << iterations; diff --git a/src/Filtering/DistanceMap/ApproxDistanceMapOfBinary/Code.cxx b/src/Filtering/DistanceMap/ApproxDistanceMapOfBinary/Code.cxx index 2a4e421d4..7653052b8 100644 --- a/src/Filtering/DistanceMap/ApproxDistanceMapOfBinary/Code.cxx +++ b/src/Filtering/DistanceMap/ApproxDistanceMapOfBinary/Code.cxx @@ -42,11 +42,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using ApproximateSignedDistanceMapImageFilterType = diff --git a/src/Filtering/DistanceMap/MaurerDistanceMapOfBinary/Code.cxx b/src/Filtering/DistanceMap/MaurerDistanceMapOfBinary/Code.cxx index 00f49e41f..d4b33dd22 100644 --- a/src/Filtering/DistanceMap/MaurerDistanceMapOfBinary/Code.cxx +++ b/src/Filtering/DistanceMap/MaurerDistanceMapOfBinary/Code.cxx @@ -42,11 +42,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using SignedMaurerDistanceMapImageFilterType = diff --git a/src/Filtering/DistanceMap/MeanDistanceBetweenAllPointsOnTwoCurves/Code.cxx b/src/Filtering/DistanceMap/MeanDistanceBetweenAllPointsOnTwoCurves/Code.cxx index ad747c9b7..e35a790a7 100644 --- a/src/Filtering/DistanceMap/MeanDistanceBetweenAllPointsOnTwoCurves/Code.cxx +++ b/src/Filtering/DistanceMap/MeanDistanceBetweenAllPointsOnTwoCurves/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileReader.h" #include "itkContourMeanDistanceImageFilter.h" #ifdef ENABLE_QUICKVIEW diff --git a/src/Filtering/DistanceMap/SignedDistanceMapOfBinary/Code.cxx b/src/Filtering/DistanceMap/SignedDistanceMapOfBinary/Code.cxx index b8a3e3d34..7f56ef20f 100644 --- a/src/Filtering/DistanceMap/SignedDistanceMapOfBinary/Code.cxx +++ b/src/Filtering/DistanceMap/SignedDistanceMapOfBinary/Code.cxx @@ -42,11 +42,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using SignedDanielssonDistanceMapImageFilterType = diff --git a/src/Filtering/FFT/ComputeForwardFFT/Code.cxx b/src/Filtering/FFT/ComputeForwardFFT/Code.cxx index ea4bb5926..694bea8dc 100644 --- a/src/Filtering/FFT/ComputeForwardFFT/Code.cxx +++ b/src/Filtering/FFT/ComputeForwardFFT/Code.cxx @@ -48,9 +48,7 @@ main(int argc, char * argv[]) using FloatPixelType = float; using FloatImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using UnsignedCharPixelType = unsigned char; using UnsignedCharImageType = itk::Image; @@ -59,7 +57,7 @@ main(int argc, char * argv[]) // multiple of small prime numbers. using PadFilterType = itk::WrapPadImageFilter; PadFilterType::Pointer padFilter = PadFilterType::New(); - padFilter->SetInput(reader->GetOutput()); + padFilter->SetInput(input); PadFilterType::SizeType padding; // Input size is [48, 62, 42]. Pad to [48, 64, 48]. padding[0] = 0; @@ -84,13 +82,9 @@ main(int argc, char * argv[]) realRescaleFilter->SetOutputMinimum(itk::NumericTraits::min()); realRescaleFilter->SetOutputMaximum(itk::NumericTraits::max()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer realWriter = WriterType::New(); - realWriter->SetFileName(realFileName); - realWriter->SetInput(realRescaleFilter->GetOutput()); try { - realWriter->Update(); + itk::WriteImage(realRescaleFilter->GetOutput(), realFileName); } catch (itk::ExceptionObject & error) { @@ -108,12 +102,9 @@ main(int argc, char * argv[]) imaginaryRescaleFilter->SetOutputMinimum(itk::NumericTraits::min()); imaginaryRescaleFilter->SetOutputMaximum(itk::NumericTraits::max()); - WriterType::Pointer complexWriter = WriterType::New(); - complexWriter->SetFileName(imaginaryFileName); - complexWriter->SetInput(imaginaryRescaleFilter->GetOutput()); try { - complexWriter->Update(); + itk::WriteImage(imaginaryRescaleFilter->GetOutput(), imaginaryFileName); } catch (itk::ExceptionObject & error) { @@ -131,12 +122,9 @@ main(int argc, char * argv[]) magnitudeRescaleFilter->SetOutputMinimum(itk::NumericTraits::min()); magnitudeRescaleFilter->SetOutputMaximum(itk::NumericTraits::max()); - WriterType::Pointer magnitudeWriter = WriterType::New(); - magnitudeWriter->SetFileName(modulusFileName); - magnitudeWriter->SetInput(magnitudeRescaleFilter->GetOutput()); try { - magnitudeWriter->Update(); + itk::WriteImage(magnitudeRescaleFilter->GetOutput(), modulusFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/FFT/ComputeImageSpectralDensity/Code.cxx b/src/Filtering/FFT/ComputeImageSpectralDensity/Code.cxx index ff1aea309..870a09309 100644 --- a/src/Filtering/FFT/ComputeImageSpectralDensity/Code.cxx +++ b/src/Filtering/FFT/ComputeImageSpectralDensity/Code.cxx @@ -44,15 +44,13 @@ main(int argc, char * argv[]) using PixelType = float; using RealImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // Some FFT filter implementations, like VNL's, need the image size to be a // multiple of small prime numbers. using PadFilterType = itk::WrapPadImageFilter; PadFilterType::Pointer padFilter = PadFilterType::New(); - padFilter->SetInput(reader->GetOutput()); + padFilter->SetInput(input); PadFilterType::SizeType padding; // Input size is [48, 62, 42]. Pad to [48, 64, 48]. padding[0] = 0; @@ -82,13 +80,9 @@ main(int argc, char * argv[]) FFTShiftFilterType::Pointer fftShiftFilter = FFTShiftFilterType::New(); fftShiftFilter->SetInput(windowingFilter->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(fftShiftFilter->GetOutput()); try { - writer->Update(); + itk::WriteImage(fftShiftFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.cxx b/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.cxx index a024f6a11..9dfce8dd1 100644 --- a/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.cxx +++ b/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.cxx @@ -42,13 +42,7 @@ main(int argc, char * argv[]) } else { - // Read the image - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } // Define some types @@ -73,12 +67,7 @@ main(int argc, char * argv[]) castFilter->SetInput(ifftFilter->GetOutput()); castFilter->Update(); - using WriterType = itk::ImageFileWriter; - - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("ifft.png"); - writer->SetInput(castFilter->GetOutput()); - writer->Update(); + itk::WriteImage(castFilter->GetOutput(), "ifft.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/FFT/FilterImageInFourierDomain/Code.cxx b/src/Filtering/FFT/FilterImageInFourierDomain/Code.cxx index 8692afb4c..3bb667ec7 100644 --- a/src/Filtering/FFT/FilterImageInFourierDomain/Code.cxx +++ b/src/Filtering/FFT/FilterImageInFourierDomain/Code.cxx @@ -51,15 +51,13 @@ main(int argc, char * argv[]) using PixelType = float; using RealImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // Some FFT filter implementations, like VNL's, need the image size to be a // multiple of small prime numbers. using PadFilterType = itk::WrapPadImageFilter; PadFilterType::Pointer padFilter = PadFilterType::New(); - padFilter->SetInput(reader->GetOutput()); + padFilter->SetInput(input); PadFilterType::SizeType padding; // Input size is [48, 62, 42]. Pad to [48, 64, 48]. padding[0] = 0; @@ -122,13 +120,9 @@ main(int argc, char * argv[]) InverseFilterType::Pointer inverseFFTFilter = InverseFilterType::New(); inverseFFTFilter->SetInput(multiplyFilter->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(inverseFFTFilter->GetOutput()); try { - writer->Update(); + itk::WriteImage(inverseFFTFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/FastMarching/CreateDistanceMapFromSeeds/Code.cxx b/src/Filtering/FastMarching/CreateDistanceMapFromSeeds/Code.cxx index 424ca169d..b6e45b7b2 100644 --- a/src/Filtering/FastMarching/CreateDistanceMapFromSeeds/Code.cxx +++ b/src/Filtering/FastMarching/CreateDistanceMapFromSeeds/Code.cxx @@ -116,14 +116,9 @@ main(int argc, char * argv[]) marcher->SetAlivePoints(adaptor->GetAlivePoints()); marcher->SetTrialPoints(adaptor->GetTrialPoints()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(marcher->GetOutput()); - writer->SetFileName(argv[1]); - try { - writer->Update(); + itk::WriteImage(marcher->GetOutput(), argv[1]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageCompare/CombineTwoImagesWithCheckerBoardPattern/Code.cxx b/src/Filtering/ImageCompare/CombineTwoImagesWithCheckerBoardPattern/Code.cxx index d3bad5184..0ab506eb2 100644 --- a/src/Filtering/ImageCompare/CombineTwoImagesWithCheckerBoardPattern/Code.cxx +++ b/src/Filtering/ImageCompare/CombineTwoImagesWithCheckerBoardPattern/Code.cxx @@ -60,14 +60,9 @@ main(int argc, char * argv[]) checkerBoardFilter->SetInput1(image1); checkerBoardFilter->SetInput2(image2); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(checkerBoardFilter->GetOutput()); - writer->SetFileName(argv[1]); - try { - writer->Update(); + itk::WriteImage(checkerBoardFilter->GetOutput(), argv[1]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageCompose/JoinImages/Code.cxx b/src/Filtering/ImageCompose/JoinImages/Code.cxx index 60a2f6b26..dbd615b4a 100644 --- a/src/Filtering/ImageCompose/JoinImages/Code.cxx +++ b/src/Filtering/ImageCompose/JoinImages/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkJoinImageFilter.h" #include "itkVectorImageToImageAdaptor.h" diff --git a/src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.cxx b/src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.cxx index be6afd981..45f1b59b8 100644 --- a/src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.cxx +++ b/src/Filtering/ImageFeature/AdditiveGaussianNoiseImageFilter/Code.cxx @@ -47,30 +47,18 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - // Read the file to be converted - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); - - using ImageType = itk::Image; + const auto input = itk::ReadImage(inputImage); // Create the filter and apply the algorithm to the image using FilterType = itk::AdditiveGaussianNoiseImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetMean(mean); // Set the mean filter->SetStandardDeviation(deviation); // Set the standard deviation - // Set the writer to save file - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputImage); - writer->SetInput(filter->GetOutput()); - - // Write the output image try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputImage); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageFeature/ApplyAFilterToASpecifiedRegionOfAnImage/Code.cxx b/src/Filtering/ImageFeature/ApplyAFilterToASpecifiedRegionOfAnImage/Code.cxx index a808007e0..0f0968b2a 100644 --- a/src/Filtering/ImageFeature/ApplyAFilterToASpecifiedRegionOfAnImage/Code.cxx +++ b/src/Filtering/ImageFeature/ApplyAFilterToASpecifiedRegionOfAnImage/Code.cxx @@ -35,29 +35,25 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using FloatImageType = itk::Image; using UnsignedCharImageType = itk::Image; - using readerType = itk::ImageFileReader; - using filterType = itk::DerivativeImageFilter; - // Create and setup a reader - readerType::Pointer reader = readerType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a derivative filter filterType::Pointer derivativeFilter = filterType::New(); - derivativeFilter->SetInput(reader->GetOutput()); + derivativeFilter->SetInput(input); derivativeFilter->SetDirection(0); // "x" axis #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(derivativeFilter->GetOutput()); viewer.Visualize(); #endif diff --git a/src/Filtering/ImageFeature/BilateralFilterAnImage/Code.cxx b/src/Filtering/ImageFeature/BilateralFilterAnImage/Code.cxx index f66887e03..5c7913528 100644 --- a/src/Filtering/ImageFeature/BilateralFilterAnImage/Code.cxx +++ b/src/Filtering/ImageFeature/BilateralFilterAnImage/Code.cxx @@ -46,32 +46,28 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using ImageType = itk::Image; - - using ReaderType = itk::ImageFileReader; using FilterType = itk::BilateralImageFilter; using SubtractImageFilterType = itk::SubtractImageFilter; - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a derivative filter FilterType::Pointer bilateralFilter = FilterType::New(); - bilateralFilter->SetInput(reader->GetOutput()); + bilateralFilter->SetInput(input); bilateralFilter->SetDomainSigma(domainSigma); bilateralFilter->SetRangeSigma(rangeSigma); SubtractImageFilterType::Pointer diff = SubtractImageFilterType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(bilateralFilter->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); std::stringstream desc; desc << "Bilateral\ndomainSigma = " << domainSigma << " rangeSigma = " << rangeSigma; diff --git a/src/Filtering/ImageFeature/ComputeLaplacian/Code.cxx b/src/Filtering/ImageFeature/ComputeLaplacian/Code.cxx index 3a10c34f7..274848cbf 100644 --- a/src/Filtering/ImageFeature/ComputeLaplacian/Code.cxx +++ b/src/Filtering/ImageFeature/ComputeLaplacian/Code.cxx @@ -43,13 +43,11 @@ main(int argc, char * argv[]) using OutputPixelType = unsigned char; using OutputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::LaplacianImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); using RescaleType = itk::RescaleIntensityImageFilter; RescaleType::Pointer rescaler = RescaleType::New(); @@ -57,14 +55,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(itk::NumericTraits::min()); rescaler->SetOutputMaximum(itk::NumericTraits::max()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageFeature/DetectEdgesWithCannyEdgeDetectionFilter/Code.cxx b/src/Filtering/ImageFeature/DetectEdgesWithCannyEdgeDetectionFilter/Code.cxx index 5746a24b5..b4c3b7924 100644 --- a/src/Filtering/ImageFeature/DetectEdgesWithCannyEdgeDetectionFilter/Code.cxx +++ b/src/Filtering/ImageFeature/DetectEdgesWithCannyEdgeDetectionFilter/Code.cxx @@ -48,13 +48,11 @@ main(int argc, char * argv[]) using InputImageType = itk::Image; using OutputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + const auto input = itk::ReadImage(inputImage); using FilterType = itk::CannyEdgeDetectionImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetVariance(variance); filter->SetLowerThreshold(lowerThreshold); filter->SetUpperThreshold(upperThreshold); @@ -65,14 +63,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(0); rescaler->SetOutputMaximum(255); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputImage); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputImage); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/ImageFeature/FindZeroCrossingsInSignedImage/Code.cxx b/src/Filtering/ImageFeature/FindZeroCrossingsInSignedImage/Code.cxx index f83a44f99..c4bb55621 100644 --- a/src/Filtering/ImageFeature/FindZeroCrossingsInSignedImage/Code.cxx +++ b/src/Filtering/ImageFeature/FindZeroCrossingsInSignedImage/Code.cxx @@ -40,11 +40,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using FilterType = itk::ZeroCrossingImageFilter; diff --git a/src/Filtering/ImageFeature/LaplacianRecursiveGaussianImageFilter/Code.cxx b/src/Filtering/ImageFeature/LaplacianRecursiveGaussianImageFilter/Code.cxx index b6845f4e5..79da30941 100644 --- a/src/Filtering/ImageFeature/LaplacianRecursiveGaussianImageFilter/Code.cxx +++ b/src/Filtering/ImageFeature/LaplacianRecursiveGaussianImageFilter/Code.cxx @@ -38,26 +38,19 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); + const auto input = itk::ReadImage(argv[1]); using OutputPixelType = float; using OutputImageType = itk::Image; using FilterType = itk::LaplacianRecursiveGaussianImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/ImageFeature/SegmentBloodVessels/Code.cxx b/src/Filtering/ImageFeature/SegmentBloodVessels/Code.cxx index e7a6d743c..50a5fae30 100644 --- a/src/Filtering/ImageFeature/SegmentBloodVessels/Code.cxx +++ b/src/Filtering/ImageFeature/SegmentBloodVessels/Code.cxx @@ -51,13 +51,11 @@ main(int argc, char * argv[]) using PixelType = float; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + const auto input = itk::ReadImage(inputImage); using HessianFilterType = itk::HessianRecursiveGaussianImageFilter; HessianFilterType::Pointer hessianFilter = HessianFilterType::New(); - hessianFilter->SetInput(reader->GetOutput()); + hessianFilter->SetInput(input); hessianFilter->SetSigma(sigma); using VesselnessMeasureFilterType = itk::Hessian3DToVesselnessMeasureImageFilter; @@ -66,14 +64,9 @@ main(int argc, char * argv[]) vesselnessFilter->SetAlpha1(alpha1); vesselnessFilter->SetAlpha2(alpha2); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(vesselnessFilter->GetOutput()); - writer->SetFileName(outputImage); - try { - writer->Update(); + itk::WriteImage(vesselnessFilter->GetOutput(), outputImage); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageFeature/SharpenImage/Code.cxx b/src/Filtering/ImageFeature/SharpenImage/Code.cxx index b48c43614..6d8d2853f 100644 --- a/src/Filtering/ImageFeature/SharpenImage/Code.cxx +++ b/src/Filtering/ImageFeature/SharpenImage/Code.cxx @@ -37,28 +37,26 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using FloatImageType = itk::Image; - using readerType = itk::ImageFileReader; - readerType::Pointer reader = readerType::New(); - reader->SetFileName(inputFilename); + const auto input = itk::ReadImage(inputFileName); using LaplacianSharpeningImageFilterType = itk::LaplacianSharpeningImageFilter; LaplacianSharpeningImageFilterType::Pointer laplacianSharpeningImageFilter = LaplacianSharpeningImageFilterType::New(); - laplacianSharpeningImageFilter->SetInput(reader->GetOutput()); + laplacianSharpeningImageFilter->SetInput(input); using SubtractType = itk::SubtractImageFilter; SubtractType::Pointer diff = SubtractType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(laplacianSharpeningImageFilter->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); std::stringstream desc; desc << "LaplacianSharpeningImageFilter"; diff --git a/src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/Code.cxx b/src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/Code.cxx index 488deef90..0b2c2da84 100644 --- a/src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/Code.cxx +++ b/src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/Code.cxx @@ -38,25 +38,18 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using OutputPixelType = float; using OutputImageType = itk::Image; using FilterType = itk::SobelEdgeDetectionImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); + filter->SetInput(input); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageFeature/ZeroCrossingBasedEdgeDecor/Code.cxx b/src/Filtering/ImageFeature/ZeroCrossingBasedEdgeDecor/Code.cxx index d78a9a08d..3579ca0ab 100644 --- a/src/Filtering/ImageFeature/ZeroCrossingBasedEdgeDecor/Code.cxx +++ b/src/Filtering/ImageFeature/ZeroCrossingBasedEdgeDecor/Code.cxx @@ -17,7 +17,6 @@ *=========================================================================*/ #include "itkImage.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkZeroCrossingBasedEdgeDetectionImageFilter.h" #include "itksys/SystemTools.hxx" @@ -44,28 +43,24 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using FloatImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - using FilterType = itk::ZeroCrossingBasedEdgeDetectionImageFilter; - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a derivative filter FilterType::Pointer edgeDetector = FilterType::New(); - edgeDetector->SetInput(reader->GetOutput()); + edgeDetector->SetInput(input); FilterType::ArrayType variance; variance.Fill(var); edgeDetector->SetVariance(variance); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename)); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(inputFilename)); std::stringstream desc; desc << "ZeroBasedEdgeDetection, variance = " << edgeDetector->GetVariance(); diff --git a/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixel/Code.cxx b/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixel/Code.cxx index a2daa7488..18b7c16d0 100644 --- a/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixel/Code.cxx +++ b/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixel/Code.cxx @@ -93,9 +93,5 @@ CastRescaleAndWrite(FloatImageType::Pointer image, const std::string & filename) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(filename); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), filename); } diff --git a/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixelInNonZeroImage/Code.cxx b/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixelInNonZeroImage/Code.cxx index 767ff81e1..24f646f5b 100644 --- a/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixelInNonZeroImage/Code.cxx +++ b/src/Filtering/ImageFilterBase/ApplyKernelToEveryPixelInNonZeroImage/Code.cxx @@ -64,11 +64,7 @@ main(int, char *[]) rescaleFilter->SetInput(maskNeighborhoodOperatorImageFilter->GetOutput()); rescaleFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -107,11 +103,7 @@ CreateHalfMask(UnsignedCharImageType::Pointer image, UnsignedCharImageType::Poin rescaleFilter->SetInput(mask); rescaleFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("mask.png"); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "mask.png"); } @@ -143,9 +135,5 @@ CreateImage(UnsignedCharImageType::Pointer image) } } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); } diff --git a/src/Filtering/ImageFilterBase/CastAnImageToAnotherType/Code.cxx b/src/Filtering/ImageFilterBase/CastAnImageToAnotherType/Code.cxx index 652b3d505..cdd79156c 100644 --- a/src/Filtering/ImageFilterBase/CastAnImageToAnotherType/Code.cxx +++ b/src/Filtering/ImageFilterBase/CastAnImageToAnotherType/Code.cxx @@ -44,13 +44,11 @@ main(int argc, char * argv[]) using InputImageType = itk::Image; using OutputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + const auto input = itk::ReadImage(inputImage); using RescaleType = itk::RescaleIntensityImageFilter; RescaleType::Pointer rescale = RescaleType::New(); - rescale->SetInput(reader->GetOutput()); + rescale->SetInput(input); rescale->SetOutputMinimum(0); rescale->SetOutputMaximum(itk::NumericTraits::max()); @@ -58,14 +56,9 @@ main(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); filter->SetInput(rescale->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputImage); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputImage); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/ImageFilterBase/ComputeLocalNoise/Code.cxx b/src/Filtering/ImageFilterBase/ComputeLocalNoise/Code.cxx index 0ff933d91..ec566ddda 100644 --- a/src/Filtering/ImageFilterBase/ComputeLocalNoise/Code.cxx +++ b/src/Filtering/ImageFilterBase/ComputeLocalNoise/Code.cxx @@ -36,11 +36,7 @@ main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) noiseImageFilter->SetRadius(1); noiseImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.mhd"); - writer->SetInput(noiseImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(noiseImageFilter->GetOutput(), "output.mhd"); return EXIT_SUCCESS; } @@ -80,9 +76,5 @@ CreateImage(ImageType::Pointer image) pixel.Fill(20); image->SetPixel(pixel, 255); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.mhd"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.mhd"); } diff --git a/src/Filtering/ImageFusion/ColorBoundariesOfRegions/Code.cxx b/src/Filtering/ImageFusion/ColorBoundariesOfRegions/Code.cxx index 728f2f5b8..143c10e29 100644 --- a/src/Filtering/ImageFusion/ColorBoundariesOfRegions/Code.cxx +++ b/src/Filtering/ImageFusion/ColorBoundariesOfRegions/Code.cxx @@ -54,11 +54,7 @@ main(int, char *[]) labelMapContourOverlayImageFilter->SetOpacity(.5); labelMapContourOverlayImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(labelMapContourOverlayImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(labelMapContourOverlayImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -99,9 +95,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/ImageFusion/ColorLabeledRegions/Code.cxx b/src/Filtering/ImageFusion/ColorLabeledRegions/Code.cxx index e305f3104..5b5c84903 100644 --- a/src/Filtering/ImageFusion/ColorLabeledRegions/Code.cxx +++ b/src/Filtering/ImageFusion/ColorLabeledRegions/Code.cxx @@ -49,11 +49,7 @@ main(int, char *[]) labelMapOverlayImageFilter->SetOpacity(.5); labelMapOverlayImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(labelMapOverlayImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(labelMapOverlayImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -94,9 +90,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); } diff --git a/src/Filtering/ImageFusion/OverlayLabelMapOnImage/Code.cxx b/src/Filtering/ImageFusion/OverlayLabelMapOnImage/Code.cxx index 70f5f4aff..6d9bd4c6b 100644 --- a/src/Filtering/ImageFusion/OverlayLabelMapOnImage/Code.cxx +++ b/src/Filtering/ImageFusion/OverlayLabelMapOnImage/Code.cxx @@ -54,11 +54,7 @@ main(int, char *[]) labelOverlayImageFilter->SetOpacity(.5); labelOverlayImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(labelOverlayImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(labelOverlayImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -99,9 +95,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); } diff --git a/src/Filtering/ImageFusion/OverlayLabelMapOnTopOfAnImage/Code.cxx b/src/Filtering/ImageFusion/OverlayLabelMapOnTopOfAnImage/Code.cxx index 046792932..e6ff92c86 100644 --- a/src/Filtering/ImageFusion/OverlayLabelMapOnTopOfAnImage/Code.cxx +++ b/src/Filtering/ImageFusion/OverlayLabelMapOnTopOfAnImage/Code.cxx @@ -44,14 +44,8 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - - ReaderType::Pointer labelReader = ReaderType::New(); - labelReader->SetFileName(labelFileName); - + const auto input = itk::ReadImage(inputFileName); + const auto label = itk::ReadImage(labelFileName); using LabelType = PixelType; using LabelObjectType = itk::LabelObject; @@ -59,22 +53,17 @@ main(int argc, char * argv[]) using ConverterType = itk::LabelImageToLabelMapFilter; ConverterType::Pointer converter = ConverterType::New(); - converter->SetInput(labelReader->GetOutput()); + converter->SetInput(label); using FilterType = itk::LabelMapOverlayImageFilter; FilterType::Pointer filter = FilterType::New(); filter->SetInput(converter->GetOutput()); - filter->SetFeatureImage(reader->GetOutput()); + filter->SetFeatureImage(input); filter->SetOpacity(0.5); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussian/Code.cxx b/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussian/Code.cxx index 927152bf6..fe0a02ecb 100644 --- a/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussian/Code.cxx +++ b/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussian/Code.cxx @@ -59,13 +59,11 @@ main(int argc, char * argv[]) using CovPixelType = itk::CovariantVector; using CovImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::GradientRecursiveGaussianImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); // Allows to select the X or Y output images using IndexSelectionType = itk::VectorIndexSelectionCastImageFilter; @@ -79,20 +77,14 @@ main(int argc, char * argv[]) rescaler->SetOutputMaximum(itk::NumericTraits::max()); rescaler->SetInput(indexSelectionFilter->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaler->GetOutput()); - // Write the X and Y images for (int i = 0; i < 2; ++i) { - - writer->SetFileName(filenames[i]); indexSelectionFilter->SetIndex(i); try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), filenames[i]); } catch (itk::ExceptionObject & error) { @@ -109,11 +101,9 @@ main(int argc, char * argv[]) // Rescale for png output rescaler->SetInput(magnitudeFilter->GetOutput()); - writer->SetFileName(outputFileNameMagnitude); - writer->SetInput(rescaler->GetOutput()); try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileNameMagnitude); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianWithVectorInput/Code.cxx b/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianWithVectorInput/Code.cxx index 212167f84..98c022f9c 100644 --- a/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianWithVectorInput/Code.cxx +++ b/src/Filtering/ImageGradient/ApplyGradientRecursiveGaussianWithVectorInput/Code.cxx @@ -64,14 +64,12 @@ main(int argc, char * argv[]) using CovPixelType = itk::CovariantVector; using CovImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // Invert the input image using InvertType = itk::InvertIntensityImageFilter; InvertType::Pointer inverter = InvertType::New(); - inverter->SetInput(reader->GetOutput()); + inverter->SetInput(input); // Cast the image to double type. using CasterType = itk::CastImageFilter; @@ -83,7 +81,7 @@ main(int argc, char * argv[]) // image using ComposeType = itk::ComposeImageFilter; ComposeType::Pointer composer = ComposeType::New(); - caster->SetInput(reader->GetOutput()); + caster->SetInput(input); composer->SetInput(0, caster->GetOutput()); caster2->SetInput(inverter->GetOutput()); composer->SetInput(1, caster2->GetOutput()); @@ -106,19 +104,14 @@ main(int argc, char * argv[]) rescaler->SetOutputMaximum(itk::NumericTraits::max()); rescaler->SetInput(indexSelectionFilter->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(rescaler->GetOutput()); - // Write the X and Y images for (int i = 0; i < 4; ++i) { indexSelectionFilter->SetIndex(i); - writer->SetFileName(filenames[i]); try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), filenames[i]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGradient/ComputeAndDisplayGradient/Code.cxx b/src/Filtering/ImageGradient/ComputeAndDisplayGradient/Code.cxx index e52fbe9c8..7d774dad1 100644 --- a/src/Filtering/ImageGradient/ComputeAndDisplayGradient/Code.cxx +++ b/src/Filtering/ImageGradient/ComputeAndDisplayGradient/Code.cxx @@ -18,7 +18,6 @@ #include "itkImage.h" #include "itkCovariantVector.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkGradientImageFilter.h" #include @@ -51,27 +50,24 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using FloatImageType = itk::Image; using UnsignedCharImageType = itk::Image; - // Create and setup a reader - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a gradient filter using GradientFilterType = itk::GradientImageFilter; GradientFilterType::Pointer gradientFilter = GradientFilterType::New(); - gradientFilter->SetInput(reader->GetOutput()); + gradientFilter->SetInput(input); gradientFilter->Update(); // Visualize original image using ConnectorType = itk::ImageToVTKImageFilter; ConnectorType::Pointer originalConnector = ConnectorType::New(); - originalConnector->SetInput(reader->GetOutput()); + originalConnector->SetInput(input); vtkSmartPointer originalActor = vtkSmartPointer::New(); originalActor->SetInput(originalConnector->GetOutput()); diff --git a/src/Filtering/ImageGradient/ComputeGradientMagnitude/Code.cxx b/src/Filtering/ImageGradient/ComputeGradientMagnitude/Code.cxx index 65c10b2a1..63132124b 100644 --- a/src/Filtering/ImageGradient/ComputeGradientMagnitude/Code.cxx +++ b/src/Filtering/ImageGradient/ComputeGradientMagnitude/Code.cxx @@ -43,25 +43,17 @@ main(int argc, char * argv[]) using OutputPixelType = float; using OutputImageType = itk::Image; - // Create and setup a reader - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); // Create and setup a gradient filter using FilterType = itk::GradientMagnitudeImageFilter; FilterType::Pointer gradientFilter = FilterType::New(); - gradientFilter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(gradientFilter->GetOutput()); + gradientFilter->SetInput(input); try { - writer->Update(); + itk::WriteImage(gradientFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGradient/ComputeGradientMagnitudeRecursiveGaussian/Code.cxx b/src/Filtering/ImageGradient/ComputeGradientMagnitudeRecursiveGaussian/Code.cxx index 3755af537..9bd69dfd1 100644 --- a/src/Filtering/ImageGradient/ComputeGradientMagnitudeRecursiveGaussian/Code.cxx +++ b/src/Filtering/ImageGradient/ComputeGradientMagnitudeRecursiveGaussian/Code.cxx @@ -40,25 +40,16 @@ main(int argc, char * argv[]) using PixelType = float; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); - - using ImageType = itk::Image; + const auto input = itk::ReadImage(inputImage); using FilterType = itk::GradientMagnitudeRecursiveGaussianImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetSigma(sigma); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputImage); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputImage); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGradient/ImplementationOfSnakes/Code.cxx b/src/Filtering/ImageGradient/ImplementationOfSnakes/Code.cxx index a1f84313d..4d540b9ca 100644 --- a/src/Filtering/ImageGradient/ImplementationOfSnakes/Code.cxx +++ b/src/Filtering/ImageGradient/ImplementationOfSnakes/Code.cxx @@ -38,7 +38,6 @@ using OutputPixelType = itk::CovariantVector; using OutputImageType = itk::Image; using FilterType = itk::GradientRecursiveGaussianImageFilter; using GradMagfilterType = itk::GradientMagnitudeImageFilter; -using ReaderType = itk::ImageFileReader; } // namespace vnl_vector @@ -70,13 +69,9 @@ main(int argc, char * argv[]) } else if (argc == 8) { - // Open the image - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[7]); try { - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[7]); w = image->GetLargestPossibleRegion().GetSize()[0]; h = image->GetLargestPossibleRegion().GetSize()[1]; } diff --git a/src/Filtering/ImageGrid/AppendTwo3DVolumes/Code.cxx b/src/Filtering/ImageGrid/AppendTwo3DVolumes/Code.cxx index a3a60227d..560e9d8bd 100644 --- a/src/Filtering/ImageGrid/AppendTwo3DVolumes/Code.cxx +++ b/src/Filtering/ImageGrid/AppendTwo3DVolumes/Code.cxx @@ -40,31 +40,22 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader1 = ReaderType::New(); - reader1->SetFileName(inputFileName1); - - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader2 = ReaderType::New(); - reader2->SetFileName(inputFileName2); + const auto input1 = itk::ReadImage(inputFileName1); + const auto input2 = itk::ReadImage(inputFileName2); using TileFilterType = itk::TileImageFilter; TileFilterType::Pointer tileFilter = TileFilterType::New(); - tileFilter->SetInput(0, reader1->GetOutput()); - tileFilter->SetInput(1, reader2->GetOutput()); + tileFilter->SetInput(0, input1); + tileFilter->SetInput(1, input2); TileFilterType::LayoutArrayType layout; layout[0] = 1; layout[1] = 1; layout[2] = 2; tileFilter->SetLayout(layout); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(tileFilter->GetOutput()); try { - writer->Update(); + itk::WriteImage(tileFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/ChangeImageOriginSpacingOrDirection/Code.cxx b/src/Filtering/ImageGrid/ChangeImageOriginSpacingOrDirection/Code.cxx index 38164a72b..18556be69 100644 --- a/src/Filtering/ImageGrid/ChangeImageOriginSpacingOrDirection/Code.cxx +++ b/src/Filtering/ImageGrid/ChangeImageOriginSpacingOrDirection/Code.cxx @@ -17,7 +17,6 @@ *=========================================================================*/ #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkVersor.h" #include "itkChangeInformationImageFilter.h" diff --git a/src/Filtering/ImageGrid/Create3DVolume/Code.cxx b/src/Filtering/ImageGrid/Create3DVolume/Code.cxx index 06e50a53d..228fc0a11 100644 --- a/src/Filtering/ImageGrid/Create3DVolume/Code.cxx +++ b/src/Filtering/ImageGrid/Create3DVolume/Code.cxx @@ -40,9 +40,6 @@ main(int argc, char * argv[]) using InputImageType = itk::Image; using OutputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - using FilterType = itk::TileImageFilter; FilterType::Pointer filter = FilterType::New(); @@ -55,11 +52,11 @@ main(int argc, char * argv[]) for (int ii = 1; ii < argc - 1; ++ii) { - reader->SetFileName(argv[ii]); + InputImageType::Pointer input; try { - reader->Update(); + input = itk::ReadImage(argv[ii]); } catch (itk::ExceptionObject & e) { @@ -67,9 +64,6 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - InputImageType::Pointer input = reader->GetOutput(); - input->DisconnectPipeline(); - filter->SetInput(ii - 1, input); } @@ -77,14 +71,9 @@ main(int argc, char * argv[]) filter->SetDefaultPixelValue(defaultValue); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[argc - 1]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[argc - 1]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/CropImageBySpecifyingRegion2/Code.cxx b/src/Filtering/ImageGrid/CropImageBySpecifyingRegion2/Code.cxx index d232c3146..fe5ce0b81 100644 --- a/src/Filtering/ImageGrid/CropImageBySpecifyingRegion2/Code.cxx +++ b/src/Filtering/ImageGrid/CropImageBySpecifyingRegion2/Code.cxx @@ -41,16 +41,12 @@ main(int argc, char * argv[]) if (argc > 1) { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + image = itk::ReadImage(argv[1]); if (argc > 2) { cropSize[0] = std::stoi(argv[2]); cropSize[1] = std::stoi(argv[3]); } - reader->Update(); - image = reader->GetOutput(); desc << itksys::SystemTools::GetFilenameName(argv[1]); } else diff --git a/src/Filtering/ImageGrid/ExtractRegionOfInterestInOneImage/Code.cxx b/src/Filtering/ImageGrid/ExtractRegionOfInterestInOneImage/Code.cxx index bbbe78eb6..f6d15b643 100644 --- a/src/Filtering/ImageGrid/ExtractRegionOfInterestInOneImage/Code.cxx +++ b/src/Filtering/ImageGrid/ExtractRegionOfInterestInOneImage/Code.cxx @@ -47,9 +47,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); ImageType::IndexType start; start[0] = startx; @@ -65,16 +63,12 @@ main(int argc, char * argv[]) using FilterType = itk::RegionOfInterestImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetRegionOfInterest(region); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx b/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx index f87aba14a..59df373a5 100644 --- a/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx +++ b/src/Filtering/ImageGrid/FitSplineIntoPointSet/Code.cxx @@ -117,11 +117,7 @@ main() outputImage->SetPixel(index, 255); } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("spline.png"); - writer->SetInput(outputImage); - writer->Update(); + itk::WriteImage(outputImage, "spline.png"); return EXIT_SUCCESS; }; diff --git a/src/Filtering/ImageGrid/FlipAnImageOverSpecifiedAxes/Code.cxx b/src/Filtering/ImageGrid/FlipAnImageOverSpecifiedAxes/Code.cxx index a5a45fbf2..e261b50f0 100644 --- a/src/Filtering/ImageGrid/FlipAnImageOverSpecifiedAxes/Code.cxx +++ b/src/Filtering/ImageGrid/FlipAnImageOverSpecifiedAxes/Code.cxx @@ -37,14 +37,12 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using FlipImageFilterType = itk::FlipImageFilter; FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New(); - flipFilter->SetInput(reader->GetOutput()); + flipFilter->SetInput(input); FlipImageFilterType::FlipAxesArrayType flipAxes; if (std::stoi(argv[3]) == 0) @@ -60,14 +58,9 @@ main(int argc, char * argv[]) flipFilter->SetFlipAxes(flipAxes); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(flipFilter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(flipFilter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/PadAnImageByMirroring/Code.cxx b/src/Filtering/ImageGrid/PadAnImageByMirroring/Code.cxx index 1c9099a71..efb8e4e81 100644 --- a/src/Filtering/ImageGrid/PadAnImageByMirroring/Code.cxx +++ b/src/Filtering/ImageGrid/PadAnImageByMirroring/Code.cxx @@ -38,9 +38,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); ImageType::SizeType lowerBound; lowerBound[0] = 20; @@ -52,18 +50,13 @@ main(int argc, char * argv[]) using FilterType = itk::MirrorPadImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetPadLowerBound(lowerBound); filter->SetPadUpperBound(upperBound); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/PadAnImageWithAConstant/Code.cxx b/src/Filtering/ImageGrid/PadAnImageWithAConstant/Code.cxx index 0bdddeac9..e8401d0e2 100644 --- a/src/Filtering/ImageGrid/PadAnImageWithAConstant/Code.cxx +++ b/src/Filtering/ImageGrid/PadAnImageWithAConstant/Code.cxx @@ -39,9 +39,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); ImageType::SizeType lowerExtendRegion; lowerExtendRegion.Fill(std::stoi(argv[3])); @@ -51,19 +49,14 @@ main(int argc, char * argv[]) using FilterType = itk::ConstantPadImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetPadLowerBound(lowerExtendRegion); filter->SetPadUpperBound(upperExtendRegion); filter->SetConstant(std::stoi(argv[5])); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/PadImageByWrapping/Code.cxx b/src/Filtering/ImageGrid/PadImageByWrapping/Code.cxx index 3d3244bce..0eac32b9c 100644 --- a/src/Filtering/ImageGrid/PadImageByWrapping/Code.cxx +++ b/src/Filtering/ImageGrid/PadImageByWrapping/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkWrapPadImageFilter.h" #include "itkImageRegionIterator.h" diff --git a/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Code.cxx b/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Code.cxx index c74711729..872ea43a6 100644 --- a/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Code.cxx +++ b/src/Filtering/ImageGrid/PasteImageIntoAnotherOne/Code.cxx @@ -48,28 +48,19 @@ main(int argc, char * argv[]) index[0] = startX; index[1] = startY; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer sourceReader = ReaderType::New(); - sourceReader->SetFileName(sourceFileName); - sourceReader->Update(); - - ReaderType::Pointer destinationReader = ReaderType::New(); - destinationReader->SetFileName(destinationFileName); + const auto source = itk::ReadImage(sourceFileName); + const auto destination = itk::ReadImage(destinationFileName); using FilterType = itk::PasteImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetSourceImage(sourceReader->GetOutput()); - filter->SetSourceRegion(sourceReader->GetOutput()->GetLargestPossibleRegion()); - filter->SetDestinationImage(destinationReader->GetOutput()); + filter->SetSourceImage(source); + filter->SetSourceRegion(source->GetLargestPossibleRegion()); + filter->SetDestinationImage(destination); filter->SetDestinationIndex(index); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/PermuteAxesOfAnImage/Code.cxx b/src/Filtering/ImageGrid/PermuteAxesOfAnImage/Code.cxx index 6a9bf3296..acafaa618 100644 --- a/src/Filtering/ImageGrid/PermuteAxesOfAnImage/Code.cxx +++ b/src/Filtering/ImageGrid/PermuteAxesOfAnImage/Code.cxx @@ -40,13 +40,11 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::PermuteAxesImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); FilterType::PermuteOrderArrayType order; order[0] = 1; @@ -54,13 +52,9 @@ main(int argc, char * argv[]) filter->SetOrder(order); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/ProcessA2DSliceOfA3DImage/Code.cxx b/src/Filtering/ImageGrid/ProcessA2DSliceOfA3DImage/Code.cxx index 57c7d37f5..3d5afe583 100644 --- a/src/Filtering/ImageGrid/ProcessA2DSliceOfA3DImage/Code.cxx +++ b/src/Filtering/ImageGrid/ProcessA2DSliceOfA3DImage/Code.cxx @@ -35,21 +35,17 @@ main(int argc, char ** argv) } using PixelType = short; - using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; // Here we recover the file names from the command line arguments - const char * inputFilename = argv[1]; - const char * outputFilename = argv[2]; + const char * inputFileName = argv[1]; + const char * outputFileName = argv[2]; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); + ImageType::Pointer inputImage; try { - reader->Update(); + inputImage = itk::ReadImage(inputFileName); } catch (itk::ExceptionObject & err) { @@ -58,15 +54,11 @@ main(int argc, char ** argv) return EXIT_FAILURE; } - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFilename); - using ExtractFilterType = itk::ExtractImageFilter; ExtractFilterType::Pointer extractFilter = ExtractFilterType::New(); extractFilter->SetDirectionCollapseToSubmatrix(); // set up the extraction region [one slice] - const ImageType * inputImage = reader->GetOutput(); ImageType::RegionType inputRegion = inputImage->GetBufferedRegion(); ImageType::SizeType size = inputRegion.GetSize(); size[2] = 1; // we extract along z direction @@ -96,11 +88,10 @@ main(int argc, char ** argv) medianFilter->UpdateLargestPossibleRegion(); const ImageType * medianImage = medianFilter->GetOutput(); pasteFilter->SetSourceRegion(medianImage->GetBufferedRegion()); - writer->SetInput(pasteFilter->GetOutput()); try { - writer->Update(); + itk::WriteImage(pasteFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & err) { diff --git a/src/Filtering/ImageGrid/ResampleAScalarImage/Code.cxx b/src/Filtering/ImageGrid/ResampleAScalarImage/Code.cxx index 38e75a239..105e5065b 100644 --- a/src/Filtering/ImageGrid/ResampleAScalarImage/Code.cxx +++ b/src/Filtering/ImageGrid/ResampleAScalarImage/Code.cxx @@ -48,12 +48,7 @@ main(int argc, char * argv[]) outputSize[dim] = std::stoi(argv[k++]); } - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - reader->UpdateOutputInformation(); - - ImageType::Pointer inputImage = reader->GetOutput(); + const auto inputImage = itk::ReadImage(inputFileName); ImageType::SizeType inputSize = inputImage->GetLargestPossibleRegion().GetSize(); std::cout << "Input Size: " << inputSize << std::endl; @@ -82,13 +77,9 @@ main(int argc, char * argv[]) filter->SetOutputOrigin(inputImage->GetOrigin()); filter->SetTransform(TransformType::New()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/ResampleAVectorImage/Code.cxx b/src/Filtering/ImageGrid/ResampleAVectorImage/Code.cxx index 07783ad36..0c805d337 100644 --- a/src/Filtering/ImageGrid/ResampleAVectorImage/Code.cxx +++ b/src/Filtering/ImageGrid/ResampleAVectorImage/Code.cxx @@ -45,9 +45,7 @@ main(int argc, char * argv[]) using PixelType = itk::RGBPixel; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::ResampleImageFilter; @@ -89,15 +87,11 @@ main(int argc, char * argv[]) size[1] = 300; // number of pixels along Y filter->SetSize(size); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/ResampleAnImage/Code.cxx b/src/Filtering/ImageGrid/ResampleAnImage/Code.cxx index 5a622c417..c7a53d0b4 100644 --- a/src/Filtering/ImageGrid/ResampleAnImage/Code.cxx +++ b/src/Filtering/ImageGrid/ResampleAnImage/Code.cxx @@ -45,12 +45,7 @@ main(int argc, char * argv[]) using ScalarType = double; using IndexValueType = typename itk::Index::IndexValueType; - using ReaderType = itk::ImageFileReader; - typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - reader->Update(); - - const typename ImageType::Pointer inputImage = reader->GetOutput(); + const typename ImageType::Pointer inputImage = itk::ReadImage(inputFileName); const typename ImageType::RegionType inputRegion = inputImage->GetLargestPossibleRegion(); const typename ImageType::SizeType inputSize = inputRegion.GetSize(); const typename ImageType::SpacingType inputSpacing = inputImage->GetSpacing(); @@ -104,14 +99,9 @@ main(int argc, char * argv[]) resampleFilter->SetOutputSpacing(outputSpacing); resampleFilter->SetOutputOrigin(outputOrigin); - using WriterType = itk::ImageFileWriter; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(resampleFilter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(resampleFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageGrid/RunImageFilterOnRegionOfImage/Code.cxx b/src/Filtering/ImageGrid/RunImageFilterOnRegionOfImage/Code.cxx index c7bd3e28e..7af21099f 100644 --- a/src/Filtering/ImageGrid/RunImageFilterOnRegionOfImage/Code.cxx +++ b/src/Filtering/ImageGrid/RunImageFilterOnRegionOfImage/Code.cxx @@ -39,18 +39,15 @@ main(int argc, char * argv[]) std::cerr << argv[0] << " InputImageFile [radius]" << std::endl; return EXIT_FAILURE; } - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; using FilterType = itk::MedianImageFilter; using SubtractType = itk::SubtractImageFilter; using PasteType = itk::PasteImageFilter; - // Create and setup a reader - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); + const auto input = itk::ReadImage(inputFileName); // Create and setup a median filter FilterType::Pointer medianFilter = FilterType::New(); @@ -61,11 +58,9 @@ main(int argc, char * argv[]) radius.Fill(atoi(argv[2])); } - reader->Update(); - itk::Size<2> processSize; - processSize[0] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] / 2; - processSize[1] = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] / 2; + processSize[0] = input->GetLargestPossibleRegion().GetSize()[0] / 2; + processSize[1] = input->GetLargestPossibleRegion().GetSize()[1] / 2; itk::Index<2> processIndex; processIndex[0] = processSize[0] / 2; @@ -74,23 +69,23 @@ main(int argc, char * argv[]) itk::ImageRegion<2> processRegion(processIndex, processSize); medianFilter->SetRadius(radius); - medianFilter->SetInput(reader->GetOutput()); + medianFilter->SetInput(input); medianFilter->GetOutput()->SetRequestedRegion(processRegion); PasteType::Pointer pasteFilter = PasteType::New(); pasteFilter->SetSourceImage(medianFilter->GetOutput()); pasteFilter->SetSourceRegion(medianFilter->GetOutput()->GetRequestedRegion()); - pasteFilter->SetDestinationImage(reader->GetOutput()); + pasteFilter->SetDestinationImage(input); pasteFilter->SetDestinationIndex(processIndex); SubtractType::Pointer diff = SubtractType::New(); - diff->SetInput1(reader->GetOutput()); + diff->SetInput1(input); diff->SetInput2(pasteFilter->GetOutput()); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename)); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(inputFileName)); std::stringstream desc; desc << "Median/PasteImageFilter, radius = " << radius; diff --git a/src/Filtering/ImageGrid/ShrinkImage/Code.cxx b/src/Filtering/ImageGrid/ShrinkImage/Code.cxx index f2a1c77d3..8f650aa42 100644 --- a/src/Filtering/ImageGrid/ShrinkImage/Code.cxx +++ b/src/Filtering/ImageGrid/ShrinkImage/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkShrinkImageFilter.h" diff --git a/src/Filtering/ImageGrid/Stack2DImagesInto3DImage/Code.cxx b/src/Filtering/ImageGrid/Stack2DImagesInto3DImage/Code.cxx index 954dcbd6f..2a07fab0d 100644 --- a/src/Filtering/ImageGrid/Stack2DImagesInto3DImage/Code.cxx +++ b/src/Filtering/ImageGrid/Stack2DImagesInto3DImage/Code.cxx @@ -35,8 +35,6 @@ main(int argc, char * argv[]) using TilerType = itk::TileImageFilter; - using WriterType = itk::ImageFileWriter; - if (argc < 4) { std::cerr << "Usage: " << std::endl; @@ -75,13 +73,9 @@ main(int argc, char * argv[]) tiler->Update(); - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(tiler->GetOutput()); - writer->SetFileName(argv[argc - 1]); - try { - writer->Update(); + itk::WriteImage(tiler->GetOutput(), argv[argc - 1]); } catch (itk::ExceptionObject & excp) { diff --git a/src/Filtering/ImageGrid/TileImagesSideBySide/Code.cxx b/src/Filtering/ImageGrid/TileImagesSideBySide/Code.cxx index a48f7f400..ebd2949a0 100644 --- a/src/Filtering/ImageGrid/TileImagesSideBySide/Code.cxx +++ b/src/Filtering/ImageGrid/TileImagesSideBySide/Code.cxx @@ -46,14 +46,8 @@ main(int argc, char * argv[]) using ImageType = itk::Image; // Read images - using ImageReaderType = itk::ImageFileReader; - ImageReaderType::Pointer reader1 = ImageReaderType::New(); - reader1->SetFileName(input1FileName); - reader1->Update(); - - ImageReaderType::Pointer reader2 = ImageReaderType::New(); - reader2->SetFileName(input2FileName); - reader2->Update(); + const auto input1 = itk::ReadImage(input1FileName); + const auto input2 = itk::ReadImage(input2FileName); // Tile the images side-by-side using TileFilterType = itk::TileImageFilter; @@ -67,22 +61,16 @@ main(int argc, char * argv[]) tileFilter->SetLayout(layout); - tileFilter->SetInput(0, reader1->GetOutput()); - tileFilter->SetInput(1, reader2->GetOutput()); + tileFilter->SetInput(0, input1); + tileFilter->SetInput(1, input2); // Set the value of output pixels which are created by mismatched size input images. // If the two images are the same height, this will not be used. unsigned char fillerValue = 128; tileFilter->SetDefaultPixelValue(fillerValue); - tileFilter->Update(); - // Write the output image - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(tileFilter->GetOutput()); - writer->SetFileName(outputFileName); - writer->Update(); + itk::WriteImage(tileFilter->GetOutput(), outputFileName); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageGrid/UpsampleAnImage/Code.cxx b/src/Filtering/ImageGrid/UpsampleAnImage/Code.cxx index 38ec4f594..7794965aa 100644 --- a/src/Filtering/ImageGrid/UpsampleAnImage/Code.cxx +++ b/src/Filtering/ImageGrid/UpsampleAnImage/Code.cxx @@ -38,19 +38,15 @@ main(int argc, char * argv[]) // Typedef's for pixel, image, reader and writer types using T_InputPixel = unsigned char; + using T_Image = itk::Image; + + const auto input = itk::ReadImage(argv[1]); // Doesn't work for RGB pixels // using T_OutputPixel = unsigned char; // using T_InputPixel = itk::CovariantVector; // using T_OutputPixel = itk::CovariantVector; - using T_Image = itk::Image; - using T_Reader = itk::ImageFileReader; - - using T_WritePixel = unsigned char; - using T_WriteImage = itk::Image; - using T_Writer = itk::ImageFileWriter; - // Typedefs for the different (numerous!) elements of the "resampling" // Identity transform. @@ -70,13 +66,6 @@ main(int argc, char * argv[]) // The resampler type itself. using T_ResampleFilter = itk::ResampleImageFilter; - - // Prepare the reader and update it right away to know the sizes beforehand. - - T_Reader::Pointer pReader = T_Reader::New(); - pReader->SetFileName(argv[1]); - pReader->Update(); - // Prepare the resampler. // Instantiate the transform and specify it should be the id transform. @@ -123,13 +112,13 @@ main(int argc, char * argv[]) unsigned int nNewHeight = std::stoi(argv[4]); // Fetch original image size. - const T_Image::RegionType & inputRegion = pReader->GetOutput()->GetLargestPossibleRegion(); + const T_Image::RegionType & inputRegion = input->GetLargestPossibleRegion(); const T_Image::SizeType & vnInputSize = inputRegion.GetSize(); unsigned int nOldWidth = vnInputSize[0]; unsigned int nOldHeight = vnInputSize[1]; // Fetch original image spacing. - const T_Image::SpacingType & vfInputSpacing = pReader->GetOutput()->GetSpacing(); + const T_Image::SpacingType & vfInputSpacing = input->GetSpacing(); // Will be {1.0, 1.0} in the usual // case. @@ -149,13 +138,10 @@ main(int argc, char * argv[]) // Specify the input. - _pResizeFilter->SetInput(pReader->GetOutput()); + _pResizeFilter->SetInput(input); // Write the result - T_Writer::Pointer pWriter = T_Writer::New(); - pWriter->SetFileName(argv[2]); - pWriter->SetInput(_pResizeFilter->GetOutput()); - pWriter->Update(); + itk::WriteImage(_pResizeFilter->GetOutput(), argv[2]); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageGrid/WarpAnImageUsingADeformationField/Code.cxx b/src/Filtering/ImageGrid/WarpAnImageUsingADeformationField/Code.cxx index 44e0a27cc..414f13582 100644 --- a/src/Filtering/ImageGrid/WarpAnImageUsingADeformationField/Code.cxx +++ b/src/Filtering/ImageGrid/WarpAnImageUsingADeformationField/Code.cxx @@ -45,19 +45,9 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; + const auto input = itk::ReadImage(inputFileName); - using FieldReaderType = itk::ImageFileReader; - - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - - FieldReaderType::Pointer fieldReader = FieldReaderType::New(); - fieldReader->SetFileName(displacementFieldFileName); - fieldReader->Update(); - - DisplacementFieldType::ConstPointer deformationField = fieldReader->GetOutput(); + const auto deformationField = itk::ReadImage(displacementFieldFileName); using FilterType = itk::WarpImageFilter; @@ -75,15 +65,11 @@ main(int argc, char * argv[]) filter->SetDisplacementField(deformationField); - filter->SetInput(reader->GetOutput()); - - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(filter->GetOutput()); - writer->SetFileName(outputFileName); + filter->SetInput(input); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/AddConstantToEveryPixel/Code.cxx b/src/Filtering/ImageIntensity/AddConstantToEveryPixel/Code.cxx index 2bed0e806..babf0608b 100644 --- a/src/Filtering/ImageIntensity/AddConstantToEveryPixel/Code.cxx +++ b/src/Filtering/ImageIntensity/AddConstantToEveryPixel/Code.cxx @@ -35,11 +35,7 @@ main(int, char *[]) addImageFilter->SetConstant2(2); addImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(addImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(addImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/ApplyAtanImageFilter/Code.cxx b/src/Filtering/ImageIntensity/ApplyAtanImageFilter/Code.cxx index b4d761194..d92101800 100644 --- a/src/Filtering/ImageIntensity/ApplyAtanImageFilter/Code.cxx +++ b/src/Filtering/ImageIntensity/ApplyAtanImageFilter/Code.cxx @@ -54,14 +54,9 @@ main(int argc, char * argv[]) FilterType::Pointer filter = FilterType::New(); filter->SetInput(randomImageSource->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[1]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[1]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/ApplyCosImageFilter/Code.cxx b/src/Filtering/ImageIntensity/ApplyCosImageFilter/Code.cxx index f3148e31b..d874e639e 100644 --- a/src/Filtering/ImageIntensity/ApplyCosImageFilter/Code.cxx +++ b/src/Filtering/ImageIntensity/ApplyCosImageFilter/Code.cxx @@ -41,22 +41,15 @@ main(int argc, char * argv[]) using PixelType = float; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::CosImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); + filter->SetInput(input); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/ApplyExpNegativeImageFilter/Code.cxx b/src/Filtering/ImageIntensity/ApplyExpNegativeImageFilter/Code.cxx index 473fa6b87..9ca1294ba 100644 --- a/src/Filtering/ImageIntensity/ApplyExpNegativeImageFilter/Code.cxx +++ b/src/Filtering/ImageIntensity/ApplyExpNegativeImageFilter/Code.cxx @@ -40,22 +40,16 @@ main(int argc, char * argv[]) using PixelType = float; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::ExpNegativeImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetFactor(k); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/ApplySinImageFilter/Code.cxx b/src/Filtering/ImageIntensity/ApplySinImageFilter/Code.cxx index 0a884b8c4..08b1171b2 100644 --- a/src/Filtering/ImageIntensity/ApplySinImageFilter/Code.cxx +++ b/src/Filtering/ImageIntensity/ApplySinImageFilter/Code.cxx @@ -41,22 +41,15 @@ main(int argc, char * argv[]) using PixelType = float; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::SinImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); + filter->SetInput(input); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/BinaryANDTwoImages/Code.cxx b/src/Filtering/ImageIntensity/BinaryANDTwoImages/Code.cxx index 762ee66fd..dd508a953 100644 --- a/src/Filtering/ImageIntensity/BinaryANDTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/BinaryANDTwoImages/Code.cxx @@ -33,18 +33,12 @@ main(int, char *[]) ImageType::Pointer image1 = ImageType::New(); CreateImage1(image1); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input1.png"); - writer->SetInput(image1); - writer->Update(); + itk::WriteImage(image1, "input1.png"); ImageType::Pointer image2 = ImageType::New(); CreateImage2(image2); - writer->SetFileName("input2.png"); - writer->SetInput(image2); - writer->Update(); + itk::WriteImage(image2, "input2.png"); using AndImageFilterType = itk::AndImageFilter; @@ -53,9 +47,7 @@ main(int, char *[]) andFilter->SetInput(1, image2); andFilter->Update(); - writer->SetFileName("output.png"); - writer->SetInput(andFilter->GetOutput()); - writer->Update(); + itk::WriteImage(andFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/BinaryORTwoImages/Code.cxx b/src/Filtering/ImageIntensity/BinaryORTwoImages/Code.cxx index e1cfb22b7..61218b389 100644 --- a/src/Filtering/ImageIntensity/BinaryORTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/BinaryORTwoImages/Code.cxx @@ -33,18 +33,12 @@ main(int, char *[]) ImageType::Pointer image1 = ImageType::New(); CreateImage1(image1); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input1.png"); - writer->SetInput(image1); - writer->Update(); + itk::WriteImage(image1, "input1.png"); ImageType::Pointer image2 = ImageType::New(); CreateImage2(image2); - writer->SetFileName("input2.png"); - writer->SetInput(image2); - writer->Update(); + itk::WriteImage(image1, "input1.png"); using OrImageFilterType = itk::OrImageFilter; OrImageFilterType::Pointer orFilter = OrImageFilterType::New(); @@ -52,9 +46,7 @@ main(int, char *[]) orFilter->SetInput(1, image2); orFilter->Update(); - writer->SetFileName("output.png"); - writer->SetInput(orFilter->GetOutput()); - writer->Update(); + itk::WriteImage(orFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/BinaryXORTwoImages/Code.cxx b/src/Filtering/ImageIntensity/BinaryXORTwoImages/Code.cxx index 52fe0f4be..8ed15e35e 100644 --- a/src/Filtering/ImageIntensity/BinaryXORTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/BinaryXORTwoImages/Code.cxx @@ -42,11 +42,7 @@ main(int, char *[]) xorFilter->SetInput2(image2); xorFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(xorFilter->GetOutput()); - writer->Update(); + itk::WriteImage(xorFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/CastImageToAnotherTypeButClampToOutput/Code.cxx b/src/Filtering/ImageIntensity/CastImageToAnotherTypeButClampToOutput/Code.cxx index 52ef25a0b..5a930b922 100644 --- a/src/Filtering/ImageIntensity/CastImageToAnotherTypeButClampToOutput/Code.cxx +++ b/src/Filtering/ImageIntensity/CastImageToAnotherTypeButClampToOutput/Code.cxx @@ -38,11 +38,7 @@ main(int argc, char * argv[]) } else // Input image argument provided { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using ClampFilterType = itk::ClampImageFilter; diff --git a/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMax/Code.cxx b/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMax/Code.cxx index 85814a042..7b12746d0 100644 --- a/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMax/Code.cxx +++ b/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMax/Code.cxx @@ -16,9 +16,7 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkMaximumImageFilter.h" -#include "itkImageFileReader.h" #include "itkImageRegionIterator.h" using ImageType = itk::Image; diff --git a/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMin/Code.cxx b/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMin/Code.cxx index 6ee4b4a99..79d0f9ce6 100644 --- a/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMin/Code.cxx +++ b/src/Filtering/ImageIntensity/CompareTwoImagesAndSetOutputPixelToMin/Code.cxx @@ -16,9 +16,7 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkMinimumImageFilter.h" -#include "itkImageFileReader.h" #include "itkImageRegionIterator.h" using ImageType = itk::Image; diff --git a/src/Filtering/ImageIntensity/ComputeEdgePotential/Code.cxx b/src/Filtering/ImageIntensity/ComputeEdgePotential/Code.cxx index 7857741b0..3d27653e9 100644 --- a/src/Filtering/ImageIntensity/ComputeEdgePotential/Code.cxx +++ b/src/Filtering/ImageIntensity/ComputeEdgePotential/Code.cxx @@ -58,11 +58,7 @@ main(int /*argc*/, char * /*argv*/[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/ComputeSigmoid/Code.cxx b/src/Filtering/ImageIntensity/ComputeSigmoid/Code.cxx index 0dea49b50..8936dc5b5 100644 --- a/src/Filtering/ImageIntensity/ComputeSigmoid/Code.cxx +++ b/src/Filtering/ImageIntensity/ComputeSigmoid/Code.cxx @@ -47,26 +47,19 @@ main(int argc, char * argv[]) const ScalarType alpha = std::stod(argv[5]); const ScalarType beta = std::stod(argv[6]); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::SigmoidImageFilter; FilterType::Pointer sigmoidFilter = FilterType::New(); - sigmoidFilter->SetInput(reader->GetOutput()); + sigmoidFilter->SetInput(input); sigmoidFilter->SetOutputMinimum(outputMinimum); sigmoidFilter->SetOutputMaximum(outputMaximum); sigmoidFilter->SetAlpha(alpha); sigmoidFilter->SetBeta(beta); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(sigmoidFilter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(sigmoidFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/ComputerMagInVectorImageToMakeMagImage/Code.cxx b/src/Filtering/ImageIntensity/ComputerMagInVectorImageToMakeMagImage/Code.cxx index 53567c799..f32496d78 100644 --- a/src/Filtering/ImageIntensity/ComputerMagInVectorImageToMakeMagImage/Code.cxx +++ b/src/Filtering/ImageIntensity/ComputerMagInVectorImageToMakeMagImage/Code.cxx @@ -34,23 +34,18 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; - std::string outputFilename = argv[2]; + std::string inputFileName = argv[1]; + std::string outputFileName = argv[2]; // Setup types using VectorImageType = itk::VectorImage; using UnsignedCharImageType = itk::Image; - // Create and setup a reader - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); - - using WriterType = itk::ImageFileWriter; + const auto input = itk::ReadImage(inputFileName); using VectorMagnitudeFilterType = itk::VectorMagnitudeImageFilter; VectorMagnitudeFilterType::Pointer magnitudeFilter = VectorMagnitudeFilterType::New(); - magnitudeFilter->SetInput(reader->GetOutput()); + magnitudeFilter->SetInput(input); // To write the magnitude image file, we should rescale the gradient values // to a reasonable range @@ -61,11 +56,7 @@ main(int argc, char * argv[]) rescaler->SetOutputMaximum(255); rescaler->SetInput(magnitudeFilter->GetOutput()); - WriterType::Pointer writer = WriterType::New(); - - writer->SetFileName(outputFilename); - writer->SetInput(rescaler->GetOutput()); - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), outputFileName); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/ConvertRGBImageToGrayscaleImage/Code.cxx b/src/Filtering/ImageIntensity/ConvertRGBImageToGrayscaleImage/Code.cxx index e6a8fad9b..0795a4fd6 100644 --- a/src/Filtering/ImageIntensity/ConvertRGBImageToGrayscaleImage/Code.cxx +++ b/src/Filtering/ImageIntensity/ConvertRGBImageToGrayscaleImage/Code.cxx @@ -39,25 +39,18 @@ main(int argc, char * argv[]) using InputPixelType = itk::RGBPixel; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using OutputPixelType = unsigned char; using OutputImageType = itk::Image; using FilterType = itk::RGBToLuminanceImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); + filter->SetInput(input); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/IntensityWindowing/Code.cxx b/src/Filtering/ImageIntensity/IntensityWindowing/Code.cxx index 3cb9e4f21..3837777fc 100644 --- a/src/Filtering/ImageIntensity/IntensityWindowing/Code.cxx +++ b/src/Filtering/ImageIntensity/IntensityWindowing/Code.cxx @@ -41,11 +41,7 @@ main(int, char *[]) filter->SetOutputMaximum(255); filter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/InverseOfMaskToImage/Code.cxx b/src/Filtering/ImageIntensity/InverseOfMaskToImage/Code.cxx index 6c7b0827a..f6ee0572a 100644 --- a/src/Filtering/ImageIntensity/InverseOfMaskToImage/Code.cxx +++ b/src/Filtering/ImageIntensity/InverseOfMaskToImage/Code.cxx @@ -40,13 +40,8 @@ main(int, char *[]) maskNegatedImageFilter->SetInput(image); maskNegatedImageFilter->SetMaskImage(mask); maskNegatedImageFilter->Update(); - ; - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(maskNegatedImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(maskNegatedImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/InvertImage/Code.cxx b/src/Filtering/ImageIntensity/InvertImage/Code.cxx index 81e05010a..7371cbd4d 100644 --- a/src/Filtering/ImageIntensity/InvertImage/Code.cxx +++ b/src/Filtering/ImageIntensity/InvertImage/Code.cxx @@ -39,11 +39,7 @@ main(int argc, char * argv[]) unsigned int maximum = 255; if (argc > 1) { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); desc << itksys::SystemTools::GetFilenameName(argv[1]); if (argc > 2) { diff --git a/src/Filtering/ImageIntensity/MaskImage/Code.cxx b/src/Filtering/ImageIntensity/MaskImage/Code.cxx index aaffe9a28..c20495696 100644 --- a/src/Filtering/ImageIntensity/MaskImage/Code.cxx +++ b/src/Filtering/ImageIntensity/MaskImage/Code.cxx @@ -47,22 +47,19 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); + const auto input = itk::ReadImage(argv[1]); ImageType::Pointer mask = ImageType::New(); - CreateHalfMask(reader->GetOutput(), mask); + CreateHalfMask(input, mask); using MaskFilterType = itk::MaskImageFilter; MaskFilterType::Pointer maskFilter = MaskFilterType::New(); - maskFilter->SetInput(reader->GetOutput()); + maskFilter->SetInput(input); maskFilter->SetMaskImage(mask); mask->Print(std::cout); # ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); std::stringstream desc; desc << "Mask"; diff --git a/src/Filtering/ImageIntensity/MultiplyImageByScalar/Code.cxx b/src/Filtering/ImageIntensity/MultiplyImageByScalar/Code.cxx index 66d0b36de..8a2a698b3 100644 --- a/src/Filtering/ImageIntensity/MultiplyImageByScalar/Code.cxx +++ b/src/Filtering/ImageIntensity/MultiplyImageByScalar/Code.cxx @@ -40,26 +40,19 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using OutputPixelType = double; using OutputImageType = itk::Image; using FilterType = itk::MultiplyImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetConstant(factor); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/MultiplyTwoImages/Code.cxx b/src/Filtering/ImageIntensity/MultiplyTwoImages/Code.cxx index 433487280..85a0c9dd5 100644 --- a/src/Filtering/ImageIntensity/MultiplyTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/MultiplyTwoImages/Code.cxx @@ -41,28 +41,20 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader1 = ReaderType::New(); - reader1->SetFileName(inputFileName1); - - ReaderType::Pointer reader2 = ReaderType::New(); - reader2->SetFileName(inputFileName2); + const auto input1 = itk::ReadImage(inputFileName1); + const auto input2 = itk::ReadImage(inputFileName2); using OutputPixelType = unsigned int; using OutputImageType = itk::Image; using FilterType = itk::MultiplyImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput1(reader1->GetOutput()); - filter->SetInput2(reader2->GetOutput()); + filter->SetInput1(input1); + filter->SetInput2(input2); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/NormalizeImage/Code.cxx b/src/Filtering/ImageIntensity/NormalizeImage/Code.cxx index 4e9f0d5e7..a0b6628ca 100644 --- a/src/Filtering/ImageIntensity/NormalizeImage/Code.cxx +++ b/src/Filtering/ImageIntensity/NormalizeImage/Code.cxx @@ -37,17 +37,15 @@ main(int argc, char * argv[]) using FloatImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using NormalizeFilterType = itk::NormalizeImageFilter; NormalizeFilterType::Pointer normalizeFilter = NormalizeFilterType::New(); - normalizeFilter->SetInput(reader->GetOutput()); + normalizeFilter->SetInput(input); using StatisticsFilterType = itk::StatisticsImageFilter; StatisticsFilterType::Pointer statistics1 = StatisticsFilterType::New(); - statistics1->SetInput(reader->GetOutput()); + statistics1->SetInput(input); StatisticsFilterType::Pointer statistics2 = StatisticsFilterType::New(); statistics2->SetInput(normalizeFilter->GetOutput()); diff --git a/src/Filtering/ImageIntensity/PixelDivisionOfTwoImages/Code.cxx b/src/Filtering/ImageIntensity/PixelDivisionOfTwoImages/Code.cxx index 929a82117..5e24b51f0 100644 --- a/src/Filtering/ImageIntensity/PixelDivisionOfTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/PixelDivisionOfTwoImages/Code.cxx @@ -42,11 +42,7 @@ main(int, char *[]) divideImageFilter->SetInput2(image2); divideImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("test.png"); - writer->SetInput(divideImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(divideImageFilter->GetOutput(), "test.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/RescaleIntensity/Code.cxx b/src/Filtering/ImageIntensity/RescaleIntensity/Code.cxx index d9d5aef86..634cbfa55 100644 --- a/src/Filtering/ImageIntensity/RescaleIntensity/Code.cxx +++ b/src/Filtering/ImageIntensity/RescaleIntensity/Code.cxx @@ -38,24 +38,17 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using FilterType = itk::RescaleIntensityImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetOutputMinimum(std::stoi(argv[3])); filter->SetOutputMaximum(std::stoi(argv[4])); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageIntensity/SquareEveryPixel/Code.cxx b/src/Filtering/ImageIntensity/SquareEveryPixel/Code.cxx index a8c33481c..187b7b9e6 100644 --- a/src/Filtering/ImageIntensity/SquareEveryPixel/Code.cxx +++ b/src/Filtering/ImageIntensity/SquareEveryPixel/Code.cxx @@ -34,11 +34,7 @@ main(int, char *[]) squareImageFilter->SetInput(image); squareImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(squareImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(squareImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/SubtractConstantFromEveryPixel/Code.cxx b/src/Filtering/ImageIntensity/SubtractConstantFromEveryPixel/Code.cxx index b5435b6b6..8a1820daa 100644 --- a/src/Filtering/ImageIntensity/SubtractConstantFromEveryPixel/Code.cxx +++ b/src/Filtering/ImageIntensity/SubtractConstantFromEveryPixel/Code.cxx @@ -35,11 +35,7 @@ main(int, char *[]) subtractConstantFromImageFilter->SetConstant2(2); subtractConstantFromImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("output.png"); - writer->SetInput(subtractConstantFromImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(subtractConstantFromImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageIntensity/SubtractTwoImages/Code.cxx b/src/Filtering/ImageIntensity/SubtractTwoImages/Code.cxx index 4d60e902e..b5dd0e292 100644 --- a/src/Filtering/ImageIntensity/SubtractTwoImages/Code.cxx +++ b/src/Filtering/ImageIntensity/SubtractTwoImages/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkSubtractImageFilter.h" diff --git a/src/Filtering/ImageIntensity/TransformVectorValuedImagePixels/Code.cxx b/src/Filtering/ImageIntensity/TransformVectorValuedImagePixels/Code.cxx index 21a1ef47f..6f7a203c8 100644 --- a/src/Filtering/ImageIntensity/TransformVectorValuedImagePixels/Code.cxx +++ b/src/Filtering/ImageIntensity/TransformVectorValuedImagePixels/Code.cxx @@ -30,28 +30,21 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - std::string inputFilename = argv[1]; - std::string outputFilename = argv[2]; + std::string inputFileName = argv[1]; + std::string outputFileName = argv[2]; using FloatImageType = itk::Image, 2>; using UnsignedCharImageType = itk::Image, 2>; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); - reader->Update(); + const auto input = itk::ReadImage(inputFileName); using VectorRescaleFilterType = itk::VectorRescaleIntensityImageFilter; VectorRescaleFilterType::Pointer rescaleFilter = VectorRescaleFilterType::New(); - rescaleFilter->SetInput(reader->GetOutput()); + rescaleFilter->SetInput(input); rescaleFilter->SetOutputMaximumMagnitude(255); rescaleFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFilename); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), outputFileName); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageLabel/ExtractBoundariesOfConnectedRegionsInBinaryImage/Code.cxx b/src/Filtering/ImageLabel/ExtractBoundariesOfConnectedRegionsInBinaryImage/Code.cxx index cff482028..3552bfb06 100644 --- a/src/Filtering/ImageLabel/ExtractBoundariesOfConnectedRegionsInBinaryImage/Code.cxx +++ b/src/Filtering/ImageLabel/ExtractBoundariesOfConnectedRegionsInBinaryImage/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkBinaryContourImageFilter.h" #ifdef ENABLE_QUICKVIEW diff --git a/src/Filtering/ImageLabel/ExtractInnerAndOuterBoundariesOfBlobsInBinaryImage/Code.cxx b/src/Filtering/ImageLabel/ExtractInnerAndOuterBoundariesOfBlobsInBinaryImage/Code.cxx index ffadccd10..4b1295993 100644 --- a/src/Filtering/ImageLabel/ExtractInnerAndOuterBoundariesOfBlobsInBinaryImage/Code.cxx +++ b/src/Filtering/ImageLabel/ExtractInnerAndOuterBoundariesOfBlobsInBinaryImage/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkInvertIntensityImageFilter.h" #include "itkBinaryContourImageFilter.h" #include "itkRescaleIntensityImageFilter.h" diff --git a/src/Filtering/ImageLabel/LabelContoursOfConnectComponent/Code.cxx b/src/Filtering/ImageLabel/LabelContoursOfConnectComponent/Code.cxx index b2d1f7abc..14c47b88d 100644 --- a/src/Filtering/ImageLabel/LabelContoursOfConnectComponent/Code.cxx +++ b/src/Filtering/ImageLabel/LabelContoursOfConnectComponent/Code.cxx @@ -51,12 +51,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } // Generate connected components diff --git a/src/Filtering/ImageStatistics/AdaptiveHistogramEqualizationImageFilter/Code.cxx b/src/Filtering/ImageStatistics/AdaptiveHistogramEqualizationImageFilter/Code.cxx index 2a5350a6a..f3ae3da7d 100644 --- a/src/Filtering/ImageStatistics/AdaptiveHistogramEqualizationImageFilter/Code.cxx +++ b/src/Filtering/ImageStatistics/AdaptiveHistogramEqualizationImageFilter/Code.cxx @@ -35,9 +35,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using FileReaderType = itk::ImageFileReader; - FileReaderType::Pointer reader = FileReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using AdaptiveHistogramEqualizationImageFilterType = itk::AdaptiveHistogramEqualizationImageFilter; AdaptiveHistogramEqualizationImageFilterType::Pointer adaptiveHistogramEqualizationImageFilter = @@ -54,16 +52,11 @@ main(int argc, char * argv[]) radius.Fill(radiusSize); adaptiveHistogramEqualizationImageFilter->SetRadius(radius); - adaptiveHistogramEqualizationImageFilter->SetInput(reader->GetOutput()); + adaptiveHistogramEqualizationImageFilter->SetInput(input); adaptiveHistogramEqualizationImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(adaptiveHistogramEqualizationImageFilter->GetOutput()); - - writer->Update(); + itk::WriteImage(adaptiveHistogramEqualizationImageFilter->GetOutput(), argv[2]); return EXIT_SUCCESS; } diff --git a/src/Filtering/ImageStatistics/ApplyAccumulateImageFilter/Code.cxx b/src/Filtering/ImageStatistics/ApplyAccumulateImageFilter/Code.cxx index 9c8b0c7f0..586ee5f83 100644 --- a/src/Filtering/ImageStatistics/ApplyAccumulateImageFilter/Code.cxx +++ b/src/Filtering/ImageStatistics/ApplyAccumulateImageFilter/Code.cxx @@ -41,26 +41,19 @@ main(int argc, char * argv[]) using InputPixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using OutputPixelType = double; using OutputImageType = itk::Image; using FilterType = itk::AccumulateImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetAccumulateDimension(accumulateDimension); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/ImageStatistics/CalculateImageMoments/Code.cxx b/src/Filtering/ImageStatistics/CalculateImageMoments/Code.cxx index 883832eaf..df9d5a9dd 100644 --- a/src/Filtering/ImageStatistics/CalculateImageMoments/Code.cxx +++ b/src/Filtering/ImageStatistics/CalculateImageMoments/Code.cxx @@ -17,7 +17,6 @@ *=========================================================================*/ #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkImageMomentsCalculator.h" int @@ -39,16 +38,13 @@ main(int argc, char * argv[]) using PixelType = unsigned short; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); - reader->Update(); + const auto input = itk::ReadImage(inputFileName); // clang-format off using FilterType = itk::ImageMomentsCalculator; // clang-format on FilterType::Pointer filter = FilterType::New(); - filter->SetImage(reader->GetOutput()); + filter->SetImage(input); filter->Compute(); filter->Print(std::cout, 0); diff --git a/src/Filtering/ImageStatistics/ComputeMinMaxVarianceMeanOfImage/Code.cxx b/src/Filtering/ImageStatistics/ComputeMinMaxVarianceMeanOfImage/Code.cxx index 607005477..d165ebe76 100644 --- a/src/Filtering/ImageStatistics/ComputeMinMaxVarianceMeanOfImage/Code.cxx +++ b/src/Filtering/ImageStatistics/ComputeMinMaxVarianceMeanOfImage/Code.cxx @@ -16,9 +16,7 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkStatisticsImageFilter.h" -#include "itkImageFileReader.h" using ImageType = itk::Image; diff --git a/src/Filtering/ImageStatistics/ComputePCAShapeFromSample/Code.cxx b/src/Filtering/ImageStatistics/ComputePCAShapeFromSample/Code.cxx index 94a618c61..854f4d111 100644 --- a/src/Filtering/ImageStatistics/ComputePCAShapeFromSample/Code.cxx +++ b/src/Filtering/ImageStatistics/ComputePCAShapeFromSample/Code.cxx @@ -65,9 +65,6 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using my_PixelType = float; using ImageType = itk::Image; - - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; using ScaleType = itk::MultiplyImageFilter; unsigned int nb_train = atoi(argv[1]); @@ -82,10 +79,7 @@ main(int argc, char * argv[]) for (unsigned int k = 0; k < nb_train; k++) { - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(shapeModeFileNames[k].c_str()); - reader->Update(); - trainingImages[k] = reader->GetOutput(); + trainingImages[k] = itk::ReadImage(shapeModeFileNames[k]); } using my_Estimatortype = itk::ImagePCAShapeModelEstimator; @@ -119,14 +113,12 @@ main(int argc, char * argv[]) double sv_n = sv / sv_mean; // double sv_n=sv; std::cout << "writing: " << outFileNames[k] << std::endl; - std::cout << "svd[" << k << "]: " << sv << " norm: " << sv_n << std::endl; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outFileNames[k].c_str()); + scaler->SetInput(filter->GetOutput(k)); scaler->SetConstant(sv_n); - writer->SetInput(scaler->GetOutput()); - writer->Update(); + + itk::WriteImage(scaler->GetOutput(), outFileNames[k]); } return EXIT_SUCCESS; diff --git a/src/Filtering/ImageStatistics/StatisticalPropertiesOfRegions/Code.cxx b/src/Filtering/ImageStatistics/StatisticalPropertiesOfRegions/Code.cxx index 1c9943f66..dca11b71e 100644 --- a/src/Filtering/ImageStatistics/StatisticalPropertiesOfRegions/Code.cxx +++ b/src/Filtering/ImageStatistics/StatisticalPropertiesOfRegions/Code.cxx @@ -113,9 +113,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/LabelMap/ApplyMorphologicalClosingOnAllLabelObjects/Code.cxx b/src/Filtering/LabelMap/ApplyMorphologicalClosingOnAllLabelObjects/Code.cxx index 49a5cc8d0..a0c725520 100644 --- a/src/Filtering/LabelMap/ApplyMorphologicalClosingOnAllLabelObjects/Code.cxx +++ b/src/Filtering/LabelMap/ApplyMorphologicalClosingOnAllLabelObjects/Code.cxx @@ -46,16 +46,14 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using LabelObjectType = itk::LabelObject; using LabelMapType = itk::LabelMap; using LabelImageToLabelMapFilterType = itk::LabelImageToLabelMapFilter; LabelImageToLabelMapFilterType::Pointer labelMapConverter = LabelImageToLabelMapFilterType::New(); - labelMapConverter->SetInput(reader->GetOutput()); + labelMapConverter->SetInput(input); labelMapConverter->SetBackgroundValue(itk::NumericTraits::Zero); using StructuringElementType = itk::FlatStructuringElement; @@ -82,13 +80,9 @@ main(int argc, char * argv[]) LabelMapToLabelImageFilterType::Pointer labelImageConverter = LabelMapToLabelImageFilterType::New(); labelImageConverter->SetInput(unique->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(labelImageConverter->GetOutput()); try { - writer->Update(); + itk::WriteImage(labelImageConverter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/LabelMap/ApplyMorphologicalClosingOnSpecificLabelObject/Code.cxx b/src/Filtering/LabelMap/ApplyMorphologicalClosingOnSpecificLabelObject/Code.cxx index f1f982b5c..9bd1bb0ff 100644 --- a/src/Filtering/LabelMap/ApplyMorphologicalClosingOnSpecificLabelObject/Code.cxx +++ b/src/Filtering/LabelMap/ApplyMorphologicalClosingOnSpecificLabelObject/Code.cxx @@ -49,16 +49,14 @@ main(int argc, char * argv[]) const auto label = static_cast(std::stoi(argv[3])); const unsigned int radiusValue = std::stoi(argv[4]); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using LabelObjectType = itk::LabelObject; using LabelMapType = itk::LabelMap; using LabelImageToLabelMapFilterType = itk::LabelImageToLabelMapFilter; LabelImageToLabelMapFilterType::Pointer labelMapConverter = LabelImageToLabelMapFilterType::New(); - labelMapConverter->SetInput(reader->GetOutput()); + labelMapConverter->SetInput(input); labelMapConverter->SetBackgroundValue(itk::NumericTraits::Zero); using SelectorType = itk::LabelSelectionLabelMapFilter; @@ -96,13 +94,9 @@ main(int argc, char * argv[]) LabelMapToLabelImageFilterType::Pointer labelImageConverter = LabelMapToLabelImageFilterType::New(); labelImageConverter->SetInput(unique->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(labelImageConverter->GetOutput()); try { - writer->Update(); + itk::WriteImage(labelImageConverter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/LabelMap/ConvertImageToLabelMap/Code.cxx b/src/Filtering/LabelMap/ConvertImageToLabelMap/Code.cxx index 08b9b7f3a..c876146ec 100644 --- a/src/Filtering/LabelMap/ConvertImageToLabelMap/Code.cxx +++ b/src/Filtering/LabelMap/ConvertImageToLabelMap/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkLabelImageToLabelMapFilter.h" #include "itkConnectedComponentImageFilter.h" diff --git a/src/Filtering/LabelMap/ConvertImageWithLabelsToShapeLabelMap/Code.cxx b/src/Filtering/LabelMap/ConvertImageWithLabelsToShapeLabelMap/Code.cxx index a5e1825b0..2b4861ede 100644 --- a/src/Filtering/LabelMap/ConvertImageWithLabelsToShapeLabelMap/Code.cxx +++ b/src/Filtering/LabelMap/ConvertImageWithLabelsToShapeLabelMap/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkLabelImageToShapeLabelMapFilter.h" #include "itkConnectedComponentImageFilter.h" diff --git a/src/Filtering/LabelMap/ConvertLabelMapToImage/Code.cxx b/src/Filtering/LabelMap/ConvertLabelMapToImage/Code.cxx index 81d5cdb09..79a168638 100644 --- a/src/Filtering/LabelMap/ConvertLabelMapToImage/Code.cxx +++ b/src/Filtering/LabelMap/ConvertLabelMapToImage/Code.cxx @@ -79,9 +79,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/LabelMap/ExtractGivenLabelObject/Code.cxx b/src/Filtering/LabelMap/ExtractGivenLabelObject/Code.cxx index 22b3190d7..d7867075b 100644 --- a/src/Filtering/LabelMap/ExtractGivenLabelObject/Code.cxx +++ b/src/Filtering/LabelMap/ExtractGivenLabelObject/Code.cxx @@ -47,16 +47,14 @@ main(int argc, char * argv[]) outputFileName[1] = argv[3]; const auto label = static_cast(std::stoi(argv[4])); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using LabelObjectType = itk::LabelObject; using LabelMapType = itk::LabelMap; using LabelImageToLabelMapFilterType = itk::LabelImageToLabelMapFilter; LabelImageToLabelMapFilterType::Pointer labelMapConverter = LabelImageToLabelMapFilterType::New(); - labelMapConverter->SetInput(reader->GetOutput()); + labelMapConverter->SetInput(input); labelMapConverter->SetBackgroundValue(itk::NumericTraits::Zero); using SelectorType = itk::LabelSelectionLabelMapFilter; @@ -70,13 +68,9 @@ main(int argc, char * argv[]) LabelMapToLabelImageFilterType::Pointer labelImageConverter = LabelMapToLabelImageFilterType::New(); labelImageConverter->SetInput(selector->GetOutput(i)); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName[i]); - writer->SetInput(labelImageConverter->GetOutput()); try { - writer->Update(); + itk::WriteImage(labelImageConverter->GetOutput(), outputFileName[i]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/LabelMap/InvertImageUsingBinaryNot/Code.cxx b/src/Filtering/LabelMap/InvertImageUsingBinaryNot/Code.cxx index 559d76c4e..b09a49e99 100644 --- a/src/Filtering/LabelMap/InvertImageUsingBinaryNot/Code.cxx +++ b/src/Filtering/LabelMap/InvertImageUsingBinaryNot/Code.cxx @@ -33,11 +33,7 @@ main(int, char *[]) ImageType::Pointer image = ImageType::New(); CreateImage(image); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); using BinaryNotImageFilterType = itk::BinaryNotImageFilter; @@ -45,9 +41,7 @@ main(int, char *[]) binaryNotFilter->SetInput(image); binaryNotFilter->Update(); - writer->SetFileName("output.png"); - writer->SetInput(binaryNotFilter->GetOutput()); - writer->Update(); + itk::WriteImage(binaryNotFilter->GetOutput(), "output.png"); #endif return EXIT_SUCCESS; diff --git a/src/Filtering/LabelMap/KeepBinaryRegionsThatMeetSpecific/Code.cxx b/src/Filtering/LabelMap/KeepBinaryRegionsThatMeetSpecific/Code.cxx index a43aa984f..2d037fbbc 100644 --- a/src/Filtering/LabelMap/KeepBinaryRegionsThatMeetSpecific/Code.cxx +++ b/src/Filtering/LabelMap/KeepBinaryRegionsThatMeetSpecific/Code.cxx @@ -40,14 +40,8 @@ main(int, char *[]) opening->SetAttribute(BinaryOpeningType::LabelObjectType::MEAN); opening->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.mhd"); - writer->SetInput(featureImage); - writer->Update(); - writer->SetFileName("output.mhd"); - writer->SetInput(opening->GetOutput()); - writer->Update(); + itk::WriteImage(featureImage, "input.mhd"); + itk::WriteImage(opening->GetOutput(), "output.mhd"); return EXIT_SUCCESS; } diff --git a/src/Filtering/LabelMap/KeepRegionsAboveLevel/Code.cxx b/src/Filtering/LabelMap/KeepRegionsAboveLevel/Code.cxx index 63a93d56a..fc5c9ad56 100644 --- a/src/Filtering/LabelMap/KeepRegionsAboveLevel/Code.cxx +++ b/src/Filtering/LabelMap/KeepRegionsAboveLevel/Code.cxx @@ -66,11 +66,7 @@ main(int, char *[]) colormapImageFilter->SetColormap(itk::ScalarToRGBColormapImageFilterEnums::RGBColormapFilter::Jet); colormapImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(colormapImageFilter->GetOutput()); - writer->SetFileName("output.png"); - writer->Update(); + itk::WriteImage(colormapImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -113,9 +109,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); } diff --git a/src/Filtering/LabelMap/KeepRegionsThatMeetSpecific/Code.cxx b/src/Filtering/LabelMap/KeepRegionsThatMeetSpecific/Code.cxx index ed72cc339..098e66f11 100644 --- a/src/Filtering/LabelMap/KeepRegionsThatMeetSpecific/Code.cxx +++ b/src/Filtering/LabelMap/KeepRegionsThatMeetSpecific/Code.cxx @@ -68,12 +68,7 @@ main(int, char *[]) colormapImageFilter->SetColormap(itk::ScalarToRGBColormapImageFilterEnums::RGBColormapFilter::Jet); colormapImageFilter->Update(); - // Write the output - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(colormapImageFilter->GetOutput()); - writer->SetFileName("output.png"); - writer->Update(); + itk::WriteImage(colormapImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/LabelMap/LabelBinaryRegionsAndGetProperties/Code.cxx b/src/Filtering/LabelMap/LabelBinaryRegionsAndGetProperties/Code.cxx index 00b06a45f..e2af69652 100644 --- a/src/Filtering/LabelMap/LabelBinaryRegionsAndGetProperties/Code.cxx +++ b/src/Filtering/LabelMap/LabelBinaryRegionsAndGetProperties/Code.cxx @@ -90,9 +90,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/LabelMap/LabelBinaryRegionsInImage/Code.cxx b/src/Filtering/LabelMap/LabelBinaryRegionsInImage/Code.cxx index 24ca195e5..b7c811740 100644 --- a/src/Filtering/LabelMap/LabelBinaryRegionsInImage/Code.cxx +++ b/src/Filtering/LabelMap/LabelBinaryRegionsInImage/Code.cxx @@ -90,9 +90,5 @@ CreateImage(ImageType::Pointer image) ++imageIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/LabelMap/MaskOneImageGivenLabelMap/Code.cxx b/src/Filtering/LabelMap/MaskOneImageGivenLabelMap/Code.cxx index 137cdba12..eb458bd3e 100644 --- a/src/Filtering/LabelMap/MaskOneImageGivenLabelMap/Code.cxx +++ b/src/Filtering/LabelMap/MaskOneImageGivenLabelMap/Code.cxx @@ -57,12 +57,9 @@ main(int argc, char * argv[]) borderSize = static_cast(std::stoi(argv[8])); } - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader1 = ReaderType::New(); - reader1->SetFileName(inputFileName); + const auto input1 = itk::ReadImage(inputFileName); - ReaderType::Pointer reader2 = ReaderType::New(); - reader2->SetFileName(labelMapFileName); + const auto input2 = itk::ReadImage(labelMapFileName); using LabelObjectType = itk::LabelObject; using LabelMapType = itk::LabelMap; @@ -70,12 +67,12 @@ main(int argc, char * argv[]) // convert the label image into a LabelMap using LabelImage2LabelMapType = itk::LabelImageToLabelMapFilter; LabelImage2LabelMapType::Pointer convert = LabelImage2LabelMapType::New(); - convert->SetInput(reader2->GetOutput()); + convert->SetInput(input2); using FilterType = itk::LabelMapMaskImageFilter; FilterType::Pointer filter = FilterType::New(); filter->SetInput(convert->GetOutput()); - filter->SetFeatureImage(reader1->GetOutput()); + filter->SetFeatureImage(input1); // The label to be used to mask the image is passed via SetLabel filter->SetLabel(label); @@ -100,14 +97,9 @@ main(int argc, char * argv[]) filter->SetCropBorder(border); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/LabelMap/RemoveHolesNotConnectedToImageBoundaries/Code.cxx b/src/Filtering/LabelMap/RemoveHolesNotConnectedToImageBoundaries/Code.cxx index ba8bbfd6f..c898351bc 100644 --- a/src/Filtering/LabelMap/RemoveHolesNotConnectedToImageBoundaries/Code.cxx +++ b/src/Filtering/LabelMap/RemoveHolesNotConnectedToImageBoundaries/Code.cxx @@ -40,22 +40,16 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::BinaryFillholeImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetForegroundValue(itk::NumericTraits::min()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/LabelMap/RemoveLabelsFromLabelMap/Code.cxx b/src/Filtering/LabelMap/RemoveLabelsFromLabelMap/Code.cxx index 5b342d05e..3fd977f96 100644 --- a/src/Filtering/LabelMap/RemoveLabelsFromLabelMap/Code.cxx +++ b/src/Filtering/LabelMap/RemoveLabelsFromLabelMap/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkImageRegionIterator.h" #include "itkBinaryImageToLabelMapFilter.h" diff --git a/src/Filtering/LabelMap/ShapeAttributesForBinaryImage/Code.cxx b/src/Filtering/LabelMap/ShapeAttributesForBinaryImage/Code.cxx index edc147e14..05c34ba31 100644 --- a/src/Filtering/LabelMap/ShapeAttributesForBinaryImage/Code.cxx +++ b/src/Filtering/LabelMap/ShapeAttributesForBinaryImage/Code.cxx @@ -45,13 +45,7 @@ main(int argc, char * argv[]) } else { - fileName = argv[1]; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(fileName); - reader->Update(); - - image = reader->GetOutput(); + image = itk::ReadImage(fileName); } diff --git a/src/Filtering/MathematicalMorphology/DilateAGrayscaleImage/Code.cxx b/src/Filtering/MathematicalMorphology/DilateAGrayscaleImage/Code.cxx index e775ffb8a..542d0e890 100644 --- a/src/Filtering/MathematicalMorphology/DilateAGrayscaleImage/Code.cxx +++ b/src/Filtering/MathematicalMorphology/DilateAGrayscaleImage/Code.cxx @@ -40,9 +40,8 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + + const auto input = itk::ReadImage(inputImage); using StructuringElementType = itk::FlatStructuringElement; StructuringElementType::RadiusType radius; @@ -52,17 +51,12 @@ main(int argc, char * argv[]) using GrayscaleDilateImageFilterType = itk::GrayscaleDilateImageFilter; GrayscaleDilateImageFilterType::Pointer dilateFilter = GrayscaleDilateImageFilterType::New(); - dilateFilter->SetInput(reader->GetOutput()); + dilateFilter->SetInput(input); dilateFilter->SetKernel(structuringElement); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(dilateFilter->GetOutput()); - writer->SetFileName(outputImage); - try { - writer->Update(); + itk::WriteImage(dilateFilter->GetOutput(), outputImage); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/MathematicalMorphology/ErodeAGrayscaleImage/Code.cxx b/src/Filtering/MathematicalMorphology/ErodeAGrayscaleImage/Code.cxx index 5535df5bd..e7c8de1a6 100644 --- a/src/Filtering/MathematicalMorphology/ErodeAGrayscaleImage/Code.cxx +++ b/src/Filtering/MathematicalMorphology/ErodeAGrayscaleImage/Code.cxx @@ -40,9 +40,8 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImage); + + const auto input = itk::ReadImage(inputImage); using StructuringElementType = itk::FlatStructuringElement; StructuringElementType::RadiusType radius; @@ -52,17 +51,12 @@ main(int argc, char * argv[]) using GrayscaleErodeImageFilterType = itk::GrayscaleErodeImageFilter; GrayscaleErodeImageFilterType::Pointer erodeFilter = GrayscaleErodeImageFilterType::New(); - erodeFilter->SetInput(reader->GetOutput()); + erodeFilter->SetInput(input); erodeFilter->SetKernel(structuringElement); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(erodeFilter->GetOutput()); - writer->SetFileName(outputImage); - try { - writer->Update(); + itk::WriteImage(erodeFilter->GetOutput(), outputImage); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/Code.cxx b/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/Code.cxx index 952160391..42abbe42f 100644 --- a/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/Code.cxx +++ b/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/Code.cxx @@ -39,9 +39,8 @@ main(int argc, char * argv[]) } using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + + const auto input = itk::ReadImage(argv[1]); using StructuringElementType = itk::FlatStructuringElement<2>; StructuringElementType::RadiusType elementRadius; @@ -52,14 +51,14 @@ main(int argc, char * argv[]) using BinaryErodeImageFilterType = itk::BinaryErodeImageFilter; BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New(); - erodeFilter->SetInput(reader->GetOutput()); + erodeFilter->SetInput(input); erodeFilter->SetKernel(structuringElement); erodeFilter->SetForegroundValue(255); // Intensity value to erode erodeFilter->SetBackgroundValue(0); // Replacement value for eroded voxels #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(erodeFilter->GetOutput()); viewer.Visualize(); #endif diff --git a/src/Filtering/MathematicalMorphology/RegionalMaximal/Code.cxx b/src/Filtering/MathematicalMorphology/RegionalMaximal/Code.cxx index 1e8a68f62..b6139f360 100644 --- a/src/Filtering/MathematicalMorphology/RegionalMaximal/Code.cxx +++ b/src/Filtering/MathematicalMorphology/RegionalMaximal/Code.cxx @@ -36,16 +36,9 @@ main(int, char *[]) RegionalMaximaImageFilter::Pointer filter = RegionalMaximaImageFilter::New(); filter->SetInput(image); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); + itk::WriteImage(image, "intensityblobs.png"); - writer->SetFileName("intensityblobs.png"); - writer->SetInput(image); - writer->Update(); - - writer->SetFileName("maximal.png"); - writer->SetInput(filter->GetOutput()); - writer->Update(); + itk::WriteImage(filter->GetOutput(), "maximal.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/MathematicalMorphology/RegionalMinimal/Code.cxx b/src/Filtering/MathematicalMorphology/RegionalMinimal/Code.cxx index eeb8d358e..e2735b866 100644 --- a/src/Filtering/MathematicalMorphology/RegionalMinimal/Code.cxx +++ b/src/Filtering/MathematicalMorphology/RegionalMinimal/Code.cxx @@ -35,15 +35,9 @@ main(int, char *[]) regionalMinimaImageFilter->SetInput(image); regionalMinimaImageFilter->Update(); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); - - writer->SetFileName("output.png"); - writer->SetInput(regionalMinimaImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(image, "input.png"); + + itk::WriteImage(regionalMinimaImageFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/MathematicalMorphology/ValuedRegionalMaximaImage/Code.cxx b/src/Filtering/MathematicalMorphology/ValuedRegionalMaximaImage/Code.cxx index 0e1a05561..7ec0f160f 100644 --- a/src/Filtering/MathematicalMorphology/ValuedRegionalMaximaImage/Code.cxx +++ b/src/Filtering/MathematicalMorphology/ValuedRegionalMaximaImage/Code.cxx @@ -36,16 +36,9 @@ main(int, char *[]) ValuedRegionalMaximaImageFilter::Pointer filter = ValuedRegionalMaximaImageFilter::New(); filter->SetInput(image); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); + itk::WriteImage( image, "intensityblobs.png"); - writer->SetFileName("intensityblobs.png"); - writer->SetInput(image); - writer->Update(); - - writer->SetFileName("maximal.png"); - writer->SetInput(filter->GetOutput()); - writer->Update(); + itk::WriteImage(filter->GetOutput(), "maximal.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/MathematicalMorphology/ValuedRegionalMinimalImage/Code.cxx b/src/Filtering/MathematicalMorphology/ValuedRegionalMinimalImage/Code.cxx index af2ab475b..f93f2c63b 100644 --- a/src/Filtering/MathematicalMorphology/ValuedRegionalMinimalImage/Code.cxx +++ b/src/Filtering/MathematicalMorphology/ValuedRegionalMinimalImage/Code.cxx @@ -35,16 +35,9 @@ main(int, char *[]) ValuedRegionalMinimaImageFilter::Pointer filter = ValuedRegionalMinimaImageFilter::New(); filter->SetInput(image); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); + itk::WriteImage(image, "input.png"); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); - - writer->SetFileName("output.png"); - writer->SetInput(filter->GetOutput()); - writer->Update(); + itk::WriteImage(filter->GetOutput(), "output.png"); return EXIT_SUCCESS; } diff --git a/src/Filtering/Path/ExtractContoursFromImage/Code.cxx b/src/Filtering/Path/ExtractContoursFromImage/Code.cxx index 0978efcb6..e053dd848 100644 --- a/src/Filtering/Path/ExtractContoursFromImage/Code.cxx +++ b/src/Filtering/Path/ExtractContoursFromImage/Code.cxx @@ -98,9 +98,5 @@ CreateImage(UnsignedCharImageType::Pointer image) image->SetPixel(pixel, 255); } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName("image.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "image.png"); } diff --git a/src/Filtering/Smoothing/BlurringAnImageUsingABinomialKernel/Code.cxx b/src/Filtering/Smoothing/BlurringAnImageUsingABinomialKernel/Code.cxx index 5cd0f1670..8bad05dcf 100644 --- a/src/Filtering/Smoothing/BlurringAnImageUsingABinomialKernel/Code.cxx +++ b/src/Filtering/Smoothing/BlurringAnImageUsingABinomialKernel/Code.cxx @@ -37,16 +37,13 @@ main(int argc, char * argv[]) using InputImageType = itk::Image; using OutputImageType = itk::Image; + const auto input = itk::ReadImage(argv[1]); + + const unsigned int repetitions = std::stoi(argv[3]); using FilterType = itk::BinomialBlurImageFilter; FilterType::Pointer filter = FilterType::New(); - - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - - reader->SetFileName(argv[1]); - const unsigned int repetitions = std::stoi(argv[3]); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetRepetitions(repetitions); filter->Update(); @@ -57,14 +54,9 @@ main(int argc, char * argv[]) RescaleFilterType::Pointer rescaler = RescaleFilterType::New(); rescaler->SetOutputMinimum(0); rescaler->SetOutputMaximum(255); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - - writer->SetFileName(argv[2]); rescaler->SetInput(filter->GetOutput()); - writer->SetInput(rescaler->GetOutput()); - writer->Update(); + + itk::WriteImage(rescaler->GetOutput(), argv[2]); return EXIT_SUCCESS; } diff --git a/src/Filtering/Smoothing/ComputesSmoothingWithGaussianKernel/Code.cxx b/src/Filtering/Smoothing/ComputesSmoothingWithGaussianKernel/Code.cxx index b9624b4a9..8afd36ba7 100644 --- a/src/Filtering/Smoothing/ComputesSmoothingWithGaussianKernel/Code.cxx +++ b/src/Filtering/Smoothing/ComputesSmoothingWithGaussianKernel/Code.cxx @@ -40,24 +40,17 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::SmoothingRecursiveGaussianImageFilter; FilterType::Pointer smoothFilter = FilterType::New(); smoothFilter->SetSigma(sigmaValue); - smoothFilter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(smoothFilter->GetOutput()); - writer->SetFileName(outputFileName); + smoothFilter->SetInput(input); try { - writer->Update(); + itk::WriteImage(smoothFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Smoothing/FindHigherDerivativesOfImage/Code.cxx b/src/Filtering/Smoothing/FindHigherDerivativesOfImage/Code.cxx index 6334d15f1..afb6940b8 100644 --- a/src/Filtering/Smoothing/FindHigherDerivativesOfImage/Code.cxx +++ b/src/Filtering/Smoothing/FindHigherDerivativesOfImage/Code.cxx @@ -17,7 +17,6 @@ *=========================================================================*/ #include "itkImage.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkRescaleIntensityImageFilter.h" #include "itkRecursiveGaussianImageFilter.h" @@ -37,29 +36,25 @@ main(int argc, char * argv[]) } // Parse command line arguments - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; // Setup types using FloatImageType = itk::Image; using UnsignedCharImageType = itk::Image; - using readerType = itk::ImageFileReader; - using filterType = itk::RecursiveGaussianImageFilter; - // Create and setup a reader - readerType::Pointer reader = readerType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a gaussian filter filterType::Pointer gaussianFilter = filterType::New(); - gaussianFilter->SetInput(reader->GetOutput()); + gaussianFilter->SetInput(input); gaussianFilter->SetDirection(0); // "x" axis gaussianFilter->SetSecondOrder(); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(gaussianFilter->GetOutput()); viewer.Visualize(); #endif diff --git a/src/Filtering/Smoothing/MeanFilteringOfAnImage/Code.cxx b/src/Filtering/Smoothing/MeanFilteringOfAnImage/Code.cxx index a40d9bf1a..e35324fd1 100644 --- a/src/Filtering/Smoothing/MeanFilteringOfAnImage/Code.cxx +++ b/src/Filtering/Smoothing/MeanFilteringOfAnImage/Code.cxx @@ -40,9 +40,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::MeanImageFilter; FilterType::Pointer meanFilter = FilterType::New(); @@ -51,16 +49,11 @@ main(int argc, char * argv[]) radius.Fill(radiusValue); meanFilter->SetRadius(radius); - meanFilter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(meanFilter->GetOutput()); - writer->SetFileName(outputFileName); + meanFilter->SetInput(input); try { - writer->Update(); + itk::WriteImage(meanFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Smoothing/MedianFilteringOfAnImage/Code.cxx b/src/Filtering/Smoothing/MedianFilteringOfAnImage/Code.cxx index 0305d9664..f9dd9d1d3 100644 --- a/src/Filtering/Smoothing/MedianFilteringOfAnImage/Code.cxx +++ b/src/Filtering/Smoothing/MedianFilteringOfAnImage/Code.cxx @@ -40,9 +40,7 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using FilterType = itk::MedianImageFilter; FilterType::Pointer medianFilter = FilterType::New(); @@ -51,16 +49,11 @@ main(int argc, char * argv[]) radius.Fill(radiusValue); medianFilter->SetRadius(radius); - medianFilter->SetInput(reader->GetOutput()); - - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(medianFilter->GetOutput()); - writer->SetFileName(outputFileName); + medianFilter->SetInput(input); try { - writer->Update(); + itk::WriteImage(medianFilter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Smoothing/MedianFilteringOfAnRGBImage/Code.cxx b/src/Filtering/Smoothing/MedianFilteringOfAnRGBImage/Code.cxx index b779748d9..f8bda88b6 100644 --- a/src/Filtering/Smoothing/MedianFilteringOfAnRGBImage/Code.cxx +++ b/src/Filtering/Smoothing/MedianFilteringOfAnRGBImage/Code.cxx @@ -70,10 +70,7 @@ main(int argc, char * argv[]) using MyPixelType = itk::myRGBPixel; using MyImageType = itk::Image; - // Create and setup a reader - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); // Create and setup a median filter using FilterType = itk::MedianImageFilter; @@ -83,7 +80,7 @@ main(int argc, char * argv[]) radius.Fill(std::stoi(argv[3])); medianFilter->SetRadius(radius); - medianFilter->SetInput(reader->GetOutput()); + medianFilter->SetInput(input); // Cast the custom myRBGPixel's to RGBPixel's using RGBPixelType = itk::RGBPixel; @@ -92,14 +89,9 @@ main(int argc, char * argv[]) CastType::Pointer cast = CastType::New(); cast->SetInput(medianFilter->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(cast->GetOutput()); - writer->SetFileName(argv[2]); - try { - writer->Update(); + itk::WriteImage(cast->GetOutput(), argv[2]); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Smoothing/SmoothImageWithDiscreteGaussianFilter/Code.cxx b/src/Filtering/Smoothing/SmoothImageWithDiscreteGaussianFilter/Code.cxx index cc58757eb..340b374d9 100644 --- a/src/Filtering/Smoothing/SmoothImageWithDiscreteGaussianFilter/Code.cxx +++ b/src/Filtering/Smoothing/SmoothImageWithDiscreteGaussianFilter/Code.cxx @@ -35,7 +35,7 @@ main(int argc, char * argv[]) } // Parse command line argumentsa - std::string inputFilename = argv[1]; + std::string inputFileName = argv[1]; double variance = 4.0; if (argc > 2) @@ -47,22 +47,18 @@ main(int argc, char * argv[]) using UnsignedCharImageType = itk::Image; using FloatImageType = itk::Image; - using readerType = itk::ImageFileReader; - using filterType = itk::DiscreteGaussianImageFilter; - // Create and setup a reader - readerType::Pointer reader = readerType::New(); - reader->SetFileName(inputFilename.c_str()); + const auto input = itk::ReadImage(inputFileName); // Create and setup a Gaussian filter filterType::Pointer gaussianFilter = filterType::New(); - gaussianFilter->SetInput(reader->GetOutput()); + gaussianFilter->SetInput(input); gaussianFilter->SetVariance(variance); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput()); + viewer.AddImage(input); viewer.AddImage(gaussianFilter->GetOutput()); viewer.Visualize(); #endif diff --git a/src/Filtering/Thresholding/DemonstrateThresholdAlgorithms/Code.cxx b/src/Filtering/Thresholding/DemonstrateThresholdAlgorithms/Code.cxx index 879070743..a7a0e84b5 100644 --- a/src/Filtering/Thresholding/DemonstrateThresholdAlgorithms/Code.cxx +++ b/src/Filtering/Thresholding/DemonstrateThresholdAlgorithms/Code.cxx @@ -29,7 +29,6 @@ #include "itkYenThresholdImageFilter.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itksys/SystemTools.hxx" #include @@ -70,14 +69,11 @@ main(int argc, char * argv[]) using TriangleFilterType = itk::TriangleThresholdImageFilter; using YenFilterType = itk::YenThresholdImageFilter; - using ReaderType = itk::ImageFileReader; - - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); #ifdef ENABLE_QUICKVIEW QuickView viewer; - viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1])); + viewer.AddImage(input, true, itksys::SystemTools::GetFilenameName(argv[1])); using FilterContainerType = std::map::Pointer>; @@ -101,7 +97,7 @@ main(int argc, char * argv[]) { (*it).second->SetInsideValue(255); (*it).second->SetOutsideValue(0); - (*it).second->SetInput(reader->GetOutput()); + (*it).second->SetInput(input); (*it).second->SetNumberOfHistogramBins(100); (*it).second->Update(); std::stringstream desc; diff --git a/src/Filtering/Thresholding/SeparateGroundUsingOtsu/Code.cxx b/src/Filtering/Thresholding/SeparateGroundUsingOtsu/Code.cxx index 22a56d6a5..61e2449ba 100644 --- a/src/Filtering/Thresholding/SeparateGroundUsingOtsu/Code.cxx +++ b/src/Filtering/Thresholding/SeparateGroundUsingOtsu/Code.cxx @@ -48,12 +48,7 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } using FilterType = itk::OtsuThresholdImageFilter; diff --git a/src/Filtering/Thresholding/ThresholdAnImage/Code.cxx b/src/Filtering/Thresholding/ThresholdAnImage/Code.cxx index e0abeebd0..913654ca0 100644 --- a/src/Filtering/Thresholding/ThresholdAnImage/Code.cxx +++ b/src/Filtering/Thresholding/ThresholdAnImage/Code.cxx @@ -40,26 +40,20 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); unsigned char lowerThreshold = std::stoi(argv[3]); unsigned char upperThreshold = std::stoi(argv[4]); using FilterType = itk::ThresholdImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->ThresholdOutside(lowerThreshold, upperThreshold); filter->SetOutsideValue(0); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(filter->GetOutput()); try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { diff --git a/src/Filtering/Thresholding/ThresholdAnImageUsingBinary/Code.cxx b/src/Filtering/Thresholding/ThresholdAnImageUsingBinary/Code.cxx index 932a31e3e..b498fc2a3 100644 --- a/src/Filtering/Thresholding/ThresholdAnImageUsingBinary/Code.cxx +++ b/src/Filtering/Thresholding/ThresholdAnImageUsingBinary/Code.cxx @@ -46,26 +46,19 @@ main(int argc, char * argv[]) using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(InputImage); + const auto input = itk::ReadImage(InputImage); using FilterType = itk::BinaryThresholdImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetLowerThreshold(LowerThreshold); filter->SetUpperThreshold(UpperThreshold); filter->SetOutsideValue(OutsideValue); filter->SetInsideValue(InsideValue); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(OutputImage); - writer->SetInput(filter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(filter->GetOutput(), OutputImage); } catch (itk::ExceptionObject & e) { diff --git a/src/Filtering/Thresholding/ThresholdAnImageUsingOtsu/Code.cxx b/src/Filtering/Thresholding/ThresholdAnImageUsingOtsu/Code.cxx index 185a00f99..7c71b4c48 100644 --- a/src/Filtering/Thresholding/ThresholdAnImageUsingOtsu/Code.cxx +++ b/src/Filtering/Thresholding/ThresholdAnImageUsingOtsu/Code.cxx @@ -46,13 +46,11 @@ main(int argc, char * argv[]) using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(InputImage); + const auto input = itk::ReadImage(InputImage); using FilterType = itk::OtsuMultipleThresholdsImageFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetNumberOfHistogramBins(NumberOfHistogramBins); filter->SetNumberOfThresholds(NumberOfThresholds); filter->SetLabelOffset(LabelOffset); @@ -74,14 +72,9 @@ main(int argc, char * argv[]) rescaler->SetOutputMinimum(0); rescaler->SetOutputMaximum(255); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(OutputImage); - writer->SetInput(rescaler->GetOutput()); - try { - writer->Update(); + itk::WriteImage(rescaler->GetOutput(), OutputImage); } catch (itk::ExceptionObject & e) {