diff --git a/src/Numerics/Optimizers/ExhaustiveOptimizer/Code.cxx b/src/Numerics/Optimizers/ExhaustiveOptimizer/Code.cxx index 0fe4b02c0..4d10ccb9b 100644 --- a/src/Numerics/Optimizers/ExhaustiveOptimizer/Code.cxx +++ b/src/Numerics/Optimizers/ExhaustiveOptimizer/Code.cxx @@ -74,16 +74,12 @@ main(int argc, char * argv[]) } using FixedImageType = itk::Image; using MovingImageType = itk::Image; - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; using TransformType = itk::Euler2DTransform; using OptimizerType = itk::ExhaustiveOptimizerv4; using MetricType = itk::MeanSquaresImageToImageMetricv4; using TransformInitializerType = itk::CenteredTransformInitializer; using RegistrationType = itk::ImageRegistrationMethodv4; - FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New(); - MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New(); FixedImageType::Pointer fixedImage = FixedImageType::New(); MovingImageType::Pointer movingImage = MovingImageType::New(); TransformType::Pointer transform = TransformType::New(); @@ -92,13 +88,8 @@ main(int argc, char * argv[]) RegistrationType::Pointer registration = RegistrationType::New(); TransformInitializerType::Pointer initializer = TransformInitializerType::New(); - fixedImageReader->SetFileName(argv[1]); - fixedImageReader->Update(); - fixedImage = fixedImageReader->GetOutput(); - - movingImageReader->SetFileName(argv[2]); - movingImageReader->Update(); - movingImage = movingImageReader->GetOutput(); + fixedImage = itk::ReadImage(argv[1]); + movingImage = itk::ReadImage(argv[2]); // Create the Command observer and register it with the optimizer. // diff --git a/src/Numerics/Statistics/ComputeHistogramFromGrayscaleImage/Code.cxx b/src/Numerics/Statistics/ComputeHistogramFromGrayscaleImage/Code.cxx index f37d04ca6..901f48fcd 100644 --- a/src/Numerics/Statistics/ComputeHistogramFromGrayscaleImage/Code.cxx +++ b/src/Numerics/Statistics/ComputeHistogramFromGrayscaleImage/Code.cxx @@ -37,11 +37,7 @@ main(int argc, char * argv[]) constexpr unsigned int MeasurementVectorSize = 1; // Grayscale const auto binsPerDimension = static_cast(std::stoi(argv[2])); - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - - ImageType::Pointer image = reader->GetOutput(); + ImageType::Pointer image = itk::ReadImage(argv[1]); using ImageToHistogramFilterType = itk::Statistics::ImageToHistogramFilter; diff --git a/src/Numerics/Statistics/ComputeHistogramOfMaskedRegion/Code.cxx b/src/Numerics/Statistics/ComputeHistogramOfMaskedRegion/Code.cxx index 42d54eafb..c73d6b03b 100644 --- a/src/Numerics/Statistics/ComputeHistogramOfMaskedRegion/Code.cxx +++ b/src/Numerics/Statistics/ComputeHistogramOfMaskedRegion/Code.cxx @@ -170,9 +170,5 @@ void CreateHalfMask(itk::ImageRegion<2> region, UnsignedCharImageType::Pointer m 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"); } diff --git a/src/Numerics/Statistics/DistributionOfPixelsUsingGMM/Code.cxx b/src/Numerics/Statistics/DistributionOfPixelsUsingGMM/Code.cxx index 3b247e9c6..adf16cc8c 100644 --- a/src/Numerics/Statistics/DistributionOfPixelsUsingGMM/Code.cxx +++ b/src/Numerics/Statistics/DistributionOfPixelsUsingGMM/Code.cxx @@ -24,7 +24,6 @@ #include "itkImageToListSampleFilter.h" #include "itkCovariantVector.h" #include "itkImageRegionIterator.h" -#include "itkImageFileReader.h" #include "itkSimpleFilterWatcher.h" using PixelType = itk::CovariantVector; diff --git a/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Code.cxx b/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Code.cxx index 893defcde..b5c122443 100644 --- a/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Code.cxx +++ b/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Code.cxx @@ -25,23 +25,15 @@ int main(int argc, char * argv[]) { using ImageType = itk::Image; - using ReaderType = itk::ImageFileReader; if (argc < 3) { std::cout << "Usage: " << argv[0] << " imageFile1 imageFile2" << std::endl; return EXIT_FAILURE; } - ReaderType::Pointer fixedReader = ReaderType::New(); - fixedReader->SetFileName(argv[1]); - fixedReader->Update(); - ReaderType::Pointer movingReader = ReaderType::New(); - movingReader->SetFileName(argv[2]); - movingReader->Update(); - - ImageType::Pointer fixedImage = fixedReader->GetOutput(); - ImageType::Pointer movingImage = movingReader->GetOutput(); + ImageType::Pointer fixedImage = itk::ReadImage(argv[1]); + ImageType::Pointer movingImage = itk::ReadImage(argv[2]); using MetricType = itk::MeanSquaresImageToImageMetric; using InterpolatorType = itk::LinearInterpolateImageFunction; diff --git a/src/Registration/Common/GlobalRegistrationOfTwoImages/Code.cxx b/src/Registration/Common/GlobalRegistrationOfTwoImages/Code.cxx index e7567696c..4b51bdf44 100644 --- a/src/Registration/Common/GlobalRegistrationOfTwoImages/Code.cxx +++ b/src/Registration/Common/GlobalRegistrationOfTwoImages/Code.cxx @@ -20,7 +20,6 @@ #include "itkImage.h" #include "itkImageRegistrationMethod.h" #include "itkLinearInterpolateImageFunction.h" -#include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkMeanSquaresImageToImageMetric.h" #include "itkRegularStepGradientDescentOptimizer.h" @@ -84,17 +83,8 @@ main(int, char *[]) CreateEllipseImage(movingImage); // Write the two synthetic inputs - using WriterType = itk::ImageFileWriter; - - WriterType::Pointer fixedWriter = WriterType::New(); - fixedWriter->SetFileName("fixed.png"); - fixedWriter->SetInput(fixedImage); - fixedWriter->Update(); - - WriterType::Pointer movingWriter = WriterType::New(); - movingWriter->SetFileName("moving.png"); - movingWriter->SetInput(movingImage); - movingWriter->Update(); + itk::WriteImage(fixedImage, "fixed.png"); + itk::WriteImage(movingImage, "moving.png"); // Set the registration inputs registration->SetFixedImage(fixedImage); @@ -211,13 +201,10 @@ main(int, char *[]) using CastFilterType = itk::CastImageFilter; - WriterType::Pointer writer = WriterType::New(); CastFilterType::Pointer caster = CastFilterType::New(); - writer->SetFileName("output.png"); - caster->SetInput(resampler->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + + itk::WriteImage(caster->GetOutput(), "output.png"); /* // The fixed image and the transformed moving image can easily be compared diff --git a/src/Registration/Common/MatchFeaturePoints/Code.cxx b/src/Registration/Common/MatchFeaturePoints/Code.cxx index 8256c7e30..46ad637e3 100644 --- a/src/Registration/Common/MatchFeaturePoints/Code.cxx +++ b/src/Registration/Common/MatchFeaturePoints/Code.cxx @@ -17,7 +17,6 @@ *=========================================================================*/ #include "itkBlockMatchingImageFilter.h" #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkPoint.h" #include "itkPointSet.h" @@ -36,12 +35,6 @@ main(int /*argc*/, char * /*argv*/[]) ImageType::Pointer movingImage = ImageType::New(); CreateImage(movingImage, 50); - // using WriterType = itk::ImageFileWriter; - // WriterType::Pointer writer = WriterType::New(); - // writer->SetFileName("input.png"); - // writer->SetInput(input); - // writer->Update(); - // using BlockMatchingImageFilterType = itk::BlockMatchingImageFilter; using BlockMatchingImageFilterType = itk::BlockMatchingImageFilter; BlockMatchingImageFilterType::Pointer blockMatchingImageFilter = BlockMatchingImageFilterType::New(); diff --git a/src/Registration/Common/MultiresolutionPyramidFromImage/Code.cxx b/src/Registration/Common/MultiresolutionPyramidFromImage/Code.cxx index d4aba6675..a2dffda93 100644 --- a/src/Registration/Common/MultiresolutionPyramidFromImage/Code.cxx +++ b/src/Registration/Common/MultiresolutionPyramidFromImage/Code.cxx @@ -54,14 +54,10 @@ main(int, char *[]) rescaleFilter->SetOutputMaximum(255); rescaleFilter->Update(); - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - std::stringstream ss; + std::stringstream ss; ss << "output_" << i << ".png"; std::cout << "Writing " << ss.str() << std::endl; - writer->SetFileName(ss.str()); - writer->SetInput(rescaleFilter->GetOutput()); - writer->Update(); + itk::WriteImage(rescaleFilter->GetOutput(), ss.str()); } return EXIT_SUCCESS; diff --git a/src/Registration/Common/MutualInformation/Code.cxx b/src/Registration/Common/MutualInformation/Code.cxx index 66b45e3ae..43eb17c95 100644 --- a/src/Registration/Common/MutualInformation/Code.cxx +++ b/src/Registration/Common/MutualInformation/Code.cxx @@ -37,22 +37,14 @@ using ImageType = itk::Image; int main(int argc, char * argv[]) { - using ReaderType = itk::ImageFileReader; - if (argc < 4) { std::cout << "Usage: " << argv[0] << " imageFile1 imageFile2 outputFile" << std::endl; return EXIT_FAILURE; } - ReaderType::Pointer fixedReader = ReaderType::New(); - fixedReader->SetFileName(argv[1]); - fixedReader->Update(); - ImageType::Pointer fixedImage = fixedReader->GetOutput(); - ReaderType::Pointer movingReader = ReaderType::New(); - movingReader->SetFileName(argv[2]); - movingReader->Update(); - ImageType::Pointer movingImage = movingReader->GetOutput(); + ImageType::Pointer fixedImage = itk::ReadImage(argv[1]); + ImageType::Pointer movingImage = itk::ReadImage(argv[2]); // We use floats internally using InternalImageType = itk::Image; @@ -240,13 +232,7 @@ main(int argc, char * argv[]) resample->SetOutputDirection(fixedImage->GetDirection()); resample->SetDefaultPixelValue(100); - // Write transformed moving image - using WriterType = itk::ImageFileWriter; - - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(argv[3]); - writer->SetInput(resample->GetOutput()); - writer->Update(); + itk::WriteImage(resample->GetOutput(), argv[3]); return EXIT_SUCCESS; } diff --git a/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Code.cxx b/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Code.cxx index ded14a9f1..5d451660c 100644 --- a/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Code.cxx +++ b/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Code.cxx @@ -55,14 +55,8 @@ main(int argc, char * argv[]) using FixedImageType = itk::Image; using MovingImageType = itk::Image; - - using FixedImageReaderType = itk::ImageFileReader; - auto fixedImageReader = FixedImageReaderType::New(); - fixedImageReader->SetFileName(fixedImageFile); - - using MovingImageReaderType = itk::ImageFileReader; - auto movingImageReader = MovingImageReaderType::New(); - movingImageReader->SetFileName(movingImageFile); + const auto fixedImage = itk::ReadImage(fixedImageFile); + const auto movingImage = itk::ReadImage(movingImageFile); using TransformType = itk::TranslationTransform; @@ -83,8 +77,8 @@ main(int argc, char * argv[]) registration->SetInitialTransform(initialTransform); registration->SetMetric(metric); registration->SetOptimizer(optimizer); - registration->SetFixedImage(fixedImageReader->GetOutput()); - registration->SetMovingImage(movingImageReader->GetOutput()); + registration->SetFixedImage(fixedImage); + registration->SetMovingImage(movingImage); auto movingInitialTransform = TransformType::New(); TransformType::ParametersType initialParameters(movingInitialTransform->GetNumberOfParameters()); @@ -145,9 +139,8 @@ main(int argc, char * argv[]) using ResampleFilterType = itk::ResampleImageFilter; auto resampler = ResampleFilterType::New(); - resampler->SetInput(movingImageReader->GetOutput()); + resampler->SetInput(movingImage); resampler->SetTransform(outputCompositeTransform); - auto fixedImage = fixedImageReader->GetOutput(); resampler->SetUseReferenceImage(true); resampler->SetReferenceImage(fixedImage); resampler->SetDefaultPixelValue(100); @@ -159,15 +152,11 @@ main(int argc, char * argv[]) auto caster = CastFilterType::New(); caster->SetInput(resampler->GetOutput()); - using WriterType = itk::ImageFileWriter; - auto writer = WriterType::New(); - writer->SetFileName(outputImageFile); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), outputImageFile); using DifferenceFilterType = itk::SubtractImageFilter; auto difference = DifferenceFilterType::New(); - difference->SetInput1(fixedImageReader->GetOutput()); + difference->SetInput1(fixedImage); difference->SetInput2(resampler->GetOutput()); using RescalerType = itk::RescaleIntensityImageFilter; @@ -177,14 +166,10 @@ main(int argc, char * argv[]) intensityRescaler->SetOutputMaximum(itk::NumericTraits::max()); resampler->SetDefaultPixelValue(1); - - writer->SetInput(intensityRescaler->GetOutput()); - writer->SetFileName(differenceImageAfterFile); - writer->Update(); + itk::WriteImage(intensityRescaler->GetOutput(), differenceImageAfterFile); resampler->SetTransform(identityTransform); - writer->SetFileName(differenceImageBeforeFile); - writer->Update(); + itk::WriteImage(intensityRescaler->GetOutput(), differenceImageBeforeFile); return EXIT_SUCCESS; } diff --git a/src/Registration/Common/PerformMultiModalityRegistrationWithMutualInformation/Code.cxx b/src/Registration/Common/PerformMultiModalityRegistrationWithMutualInformation/Code.cxx index 7f75f58f5..09740d864 100644 --- a/src/Registration/Common/PerformMultiModalityRegistrationWithMutualInformation/Code.cxx +++ b/src/Registration/Common/PerformMultiModalityRegistrationWithMutualInformation/Code.cxx @@ -156,14 +156,8 @@ main(int argc, char * argv[]) metric->SetFixedImageStandardDeviation(0.4); metric->SetMovingImageStandardDeviation(0.4); - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; - - FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New(); - MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(fixedImageFile); - movingImageReader->SetFileName(movingImageFile); + const auto fixedImage = itk::ReadImage(fixedImageFile); + const auto movingImage = itk::ReadImage(movingImageFile); using FixedNormalizeFilterType = itk::NormalizeImageFilter; @@ -181,8 +175,8 @@ main(int argc, char * argv[]) fixedSmoother->SetVariance(2.0); movingSmoother->SetVariance(2.0); - fixedNormalizer->SetInput(fixedImageReader->GetOutput()); - movingNormalizer->SetInput(movingImageReader->GetOutput()); + fixedNormalizer->SetInput(fixedImage); + movingNormalizer->SetInput(movingImage); fixedSmoother->SetInput(fixedNormalizer->GetOutput()); movingSmoother->SetInput(movingNormalizer->GetOutput()); @@ -310,10 +304,7 @@ main(int argc, char * argv[]) ResampleFilterType::Pointer resample = ResampleFilterType::New(); resample->SetTransform(finalTransform); - resample->SetInput(movingImageReader->GetOutput()); - - FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); - + resample->SetInput(movingImage); resample->SetSize(fixedImage->GetLargestPossibleRegion().GetSize()); resample->SetOutputOrigin(fixedImage->GetOrigin()); resample->SetOutputSpacing(fixedImage->GetSpacing()); @@ -327,27 +318,19 @@ main(int argc, char * argv[]) using CastFilterType = itk::CastImageFilter; - using WriterType = itk::ImageFileWriter; - - WriterType::Pointer writer = WriterType::New(); CastFilterType::Pointer caster = CastFilterType::New(); - - writer->SetFileName(outputImageFile); caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), outputImageFile); // Generate checkerboards before and after registration using CheckerBoardFilterType = itk::CheckerBoardImageFilter; CheckerBoardFilterType::Pointer checker = CheckerBoardFilterType::New(); - checker->SetInput1(fixedImage); checker->SetInput2(resample->GetOutput()); caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); // Before registration TransformType::Pointer identityTransform = TransformType::New(); @@ -356,24 +339,14 @@ main(int argc, char * argv[]) if (argc > 4) { - writer->SetFileName(checkerBoardBefore); + itk::WriteImage(caster->GetOutput(), checkerBoardBefore); } // After registration resample->SetTransform(finalTransform); if (argc > 5) { - writer->SetFileName(checkerBoardAfter); - } - - try - { - writer->Update(); - } - catch (itk::ExceptionObject & error) - { - std::cerr << "Error: " << error << std::endl; - return EXIT_FAILURE; + itk::WriteImage(caster->GetOutput(), checkerBoardAfter); } return EXIT_SUCCESS; diff --git a/src/Registration/Common/RegisterImageToAnotherUsingLandmarks/Code.cxx b/src/Registration/Common/RegisterImageToAnotherUsingLandmarks/Code.cxx index 140b6122b..0a77ecac2 100644 --- a/src/Registration/Common/RegisterImageToAnotherUsingLandmarks/Code.cxx +++ b/src/Registration/Common/RegisterImageToAnotherUsingLandmarks/Code.cxx @@ -101,12 +101,7 @@ main(int itkNotUsed(argc), char * itkNotUsed(argv)[]) resampleFilter->SetReferenceImage(fixedImage); resampleFilter->SetDefaultPixelValue(200); - // Write the output - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(resampleFilter->GetOutput()); - writer->SetFileName("output.png"); - writer->Update(); + itk::WriteImage(resampleFilter->GetOutput(), "output.png"); return EXIT_SUCCESS; } @@ -141,12 +136,7 @@ CreateFixedImage(ImageType::Pointer image) ++imageIterator; } - // Write the deformation field - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(image); - writer->SetFileName("fixed.png"); - writer->Update(); + itk::WriteImage(image, "fixed.png"); } @@ -180,10 +170,5 @@ CreateMovingImage(ImageType::Pointer image) ++imageIterator; } - // Write the deformation field - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetInput(image); - writer->SetFileName("moving.png"); - writer->Update(); + itk::WriteImage(image, "moving.png"); } diff --git a/src/Registration/Common/WatchRegistration/Code.cxx b/src/Registration/Common/WatchRegistration/Code.cxx index 0c2812cb1..10223712e 100644 --- a/src/Registration/Common/WatchRegistration/Code.cxx +++ b/src/Registration/Common/WatchRegistration/Code.cxx @@ -135,16 +135,8 @@ main(int argc, char * argv[]) if (argc > 2) { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer fixedReader = ReaderType::New(); - fixedReader->SetFileName(argv[1]); - fixedReader->Update(); - fixedImage = fixedReader->GetOutput(); - - ReaderType::Pointer movingReader = ReaderType::New(); - movingReader->SetFileName(argv[2]); - movingReader->Update(); - movingImage = movingReader->GetOutput(); + fixedImage = itk::ReadImage(argv[1]); + movingImage = itk::ReadImage(argv[2]); } else { diff --git a/src/Registration/Metricsv4/PerformRegistrationOnVectorImages/Code.cxx b/src/Registration/Metricsv4/PerformRegistrationOnVectorImages/Code.cxx index 2195fe73e..76eeb1ff6 100644 --- a/src/Registration/Metricsv4/PerformRegistrationOnVectorImages/Code.cxx +++ b/src/Registration/Metricsv4/PerformRegistrationOnVectorImages/Code.cxx @@ -70,25 +70,8 @@ main(int argc, char * argv[]) using ParametersValueType = double; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer fixedImageReader = ReaderType::New(); - fixedImageReader->SetFileName(fixedImageFile); - ReaderType::Pointer movingImageReader = ReaderType::New(); - movingImageReader->SetFileName(movingImageFile); - - // Get the input images - try - { - fixedImageReader->Update(); - movingImageReader->Update(); - } - catch (itk::ExceptionObject & error) - { - std::cerr << "Error while reading images: " << error << std::endl; - return EXIT_FAILURE; - } - InputImageType::Pointer fixedImage = fixedImageReader->GetOutput(); - InputImageType::Pointer movingImage = movingImageReader->GetOutput(); + InputImageType::Pointer fixedImage = itk::ReadImage(fixedImageFile); + InputImageType::Pointer movingImage = itk::ReadImage(movingImageFile); using AffineTransformType = itk::AffineTransform; AffineTransformType::Pointer affineTransform = AffineTransformType::New(); @@ -220,7 +203,7 @@ main(int argc, char * argv[]) using ResampleFilterType = itk::ResampleImageFilter; ResampleFilterType::Pointer resampler = ResampleFilterType::New(); resampler->SetTransform(compositeTransform); - resampler->SetInput(movingImageReader->GetOutput()); + resampler->SetInput(movingImage); resampler->SetReferenceImage(fixedImage); resampler->SetUseReferenceImage(true); @@ -231,13 +214,9 @@ main(int argc, char * argv[]) CastFilterType::Pointer caster = CastFilterType::New(); caster->SetInput(resampler->GetOutput()); - using WriterType = itk::ImageFileWriter; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(resampledMovingImageFile); - writer->SetInput(caster->GetOutput()); try { - writer->UpdateLargestPossibleRegion(); + itk::WriteImage(caster->GetOutput(), resampledMovingImageFile); } catch (itk::ExceptionObject & error) { diff --git a/src/Segmentation/Classifiers/ClusterPixelsInGrayscaleImage/Code.cxx b/src/Segmentation/Classifiers/ClusterPixelsInGrayscaleImage/Code.cxx index 30645dee4..aa4062fd9 100644 --- a/src/Segmentation/Classifiers/ClusterPixelsInGrayscaleImage/Code.cxx +++ b/src/Segmentation/Classifiers/ClusterPixelsInGrayscaleImage/Code.cxx @@ -15,8 +15,6 @@ * limitations under the License. * *=========================================================================*/ -#include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itkScalarImageKmeansImageFilter.h" #include "itkRelabelComponentImageFilter.h" #include "itkRescaleIntensityImageFilter.h" diff --git a/src/Segmentation/Classifiers/KMeansClusterOfPixelsInImage/Code.cxx b/src/Segmentation/Classifiers/KMeansClusterOfPixelsInImage/Code.cxx index d6e91b885..9c07df0fc 100644 --- a/src/Segmentation/Classifiers/KMeansClusterOfPixelsInImage/Code.cxx +++ b/src/Segmentation/Classifiers/KMeansClusterOfPixelsInImage/Code.cxx @@ -128,17 +128,8 @@ main(int, char *[]) ++outputIterator; } - using WriterType = itk::ImageFileWriter; - WriterType::Pointer inputWriter = WriterType::New(); - inputWriter->SetFileName("input.mha"); - inputWriter->SetInput(image); - inputWriter->Update(); - - using ScalarWriterType = itk::ImageFileWriter; - ScalarWriterType::Pointer outputWriter = ScalarWriterType::New(); - outputWriter->SetFileName("output.mha"); - outputWriter->SetInput(outputImage); - outputWriter->Update(); + itk::WriteImage(image, "input.mha"); + itk::WriteImage(outputImage, "output.mha"); return EXIT_SUCCESS; diff --git a/src/Segmentation/Classifiers/KMeansClustering/Code.cxx b/src/Segmentation/Classifiers/KMeansClustering/Code.cxx index 1c7aad40c..9a7e08d83 100644 --- a/src/Segmentation/Classifiers/KMeansClustering/Code.cxx +++ b/src/Segmentation/Classifiers/KMeansClustering/Code.cxx @@ -65,20 +65,16 @@ main(int argc, char * argv[]) using PixelType = signed short; constexpr unsigned int Dimension = 2; - using ImageType = itk::Image; - // create a reader - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageFileName); + const auto input = itk::ReadImage(inputImageFileName); // Instantiate the ScalarImageKmeansImageFilter using KMeansFilterType = itk::ScalarImageKmeansImageFilter; KMeansFilterType::Pointer kmeansFilter = KMeansFilterType::New(); - kmeansFilter->SetInput(reader->GetOutput()); + kmeansFilter->SetInput(input); // Make the output image intellegable by expanding the range of output image values, if desired @@ -91,22 +87,9 @@ main(int argc, char * argv[]) kmeansFilter->AddClassWithInitialMean(userMeans[k]); } - // Create and setup a writer - - using OutputImageType = KMeansFilterType::OutputImageType; - - using WriterType = itk::ImageFileWriter; - - WriterType::Pointer writer = WriterType::New(); - - writer->SetInput(kmeansFilter->GetOutput()); - - writer->SetFileName(outputImageFileName); - - // execut the pipeline try { - writer->Update(); + itk::WriteImage(kmeansFilter->GetOutput(), outputImageFileName); } catch (itk::ExceptionObject & excp) { diff --git a/src/Segmentation/ConnectedComponents/AssignContiguousLabelsToConnectedRegions/Code.cxx b/src/Segmentation/ConnectedComponents/AssignContiguousLabelsToConnectedRegions/Code.cxx index fe6a006ae..c4f9f2727 100644 --- a/src/Segmentation/ConnectedComponents/AssignContiguousLabelsToConnectedRegions/Code.cxx +++ b/src/Segmentation/ConnectedComponents/AssignContiguousLabelsToConnectedRegions/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileReader.h" #include "itkCustomColormapFunction.h" #include "itkScalarToRGBColormapImageFilter.h" #include "itkRGBPixel.h" diff --git a/src/Segmentation/ConnectedComponents/ExtraLargestConnectComponentFromBinaryImage/Code.cxx b/src/Segmentation/ConnectedComponents/ExtraLargestConnectComponentFromBinaryImage/Code.cxx index 0e21ba147..2ac2205a8 100644 --- a/src/Segmentation/ConnectedComponents/ExtraLargestConnectComponentFromBinaryImage/Code.cxx +++ b/src/Segmentation/ConnectedComponents/ExtraLargestConnectComponentFromBinaryImage/Code.cxx @@ -40,16 +40,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(argv[1]); + const auto input = itk::ReadImage(argv[1]); using OutputImageType = itk::Image; using ConnectedComponentImageFilterType = itk::ConnectedComponentImageFilter; ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New(); - connected->SetInput(reader->GetOutput()); + connected->SetInput(input); connected->Update(); std::cout << "Number of objects: " << connected->GetObjectCount() << std::endl; @@ -71,7 +69,7 @@ main(int argc, char * argv[]) #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 << "Largest object of " << connected->GetObjectCount() << " objects"; diff --git a/src/Segmentation/ConnectedComponents/LabelConnectComponentsInBinaryImage/Code.cxx b/src/Segmentation/ConnectedComponents/LabelConnectComponentsInBinaryImage/Code.cxx index 8807f864a..6bb7dd3b1 100644 --- a/src/Segmentation/ConnectedComponents/LabelConnectComponentsInBinaryImage/Code.cxx +++ b/src/Segmentation/ConnectedComponents/LabelConnectComponentsInBinaryImage/Code.cxx @@ -31,7 +31,6 @@ #include "itkConnectedComponentImageFilter.h" #include "itkLabelToRGBImageFilter.h" #include "itkImageFileReader.h" -#include "itkImageFileWriter.h" #include "itksys/SystemTools.hxx" #include @@ -76,14 +75,11 @@ main(int argc, char * argv[]) using ConnectedComponentImageFilterType = itk::ConnectedComponentImageFilter; using RGBFilterType = itk::LabelToRGBImageFilter; - 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>; @@ -108,7 +104,7 @@ main(int argc, char * argv[]) (*it).second->SetInsideValue(255); (*it).second->SetOutsideValue(0); (*it).second->SetNumberOfHistogramBins(25); - (*it).second->SetInput(reader->GetOutput()); + (*it).second->SetInput(input); try { (*it).second->Update(); diff --git a/src/Segmentation/ConnectedComponents/LabelConnectComponentsInGrayscaleImage/Code.cxx b/src/Segmentation/ConnectedComponents/LabelConnectComponentsInGrayscaleImage/Code.cxx index b6bb57783..2fb8489b8 100644 --- a/src/Segmentation/ConnectedComponents/LabelConnectComponentsInGrayscaleImage/Code.cxx +++ b/src/Segmentation/ConnectedComponents/LabelConnectComponentsInGrayscaleImage/Code.cxx @@ -60,16 +60,11 @@ main(int argc, char * argv[]) } else { - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[1]); - reader->Update(); - if (argc > 2) { distanceThreshold = static_cast(atoi(argv[2])); } - image = reader->GetOutput(); + image = itk::ReadImage(argv[1]); } diff --git a/src/Segmentation/KLMRegionGrowing/BasicRegionGrowing/Code.cxx b/src/Segmentation/KLMRegionGrowing/BasicRegionGrowing/Code.cxx index 2859b732b..451938ff9 100644 --- a/src/Segmentation/KLMRegionGrowing/BasicRegionGrowing/Code.cxx +++ b/src/Segmentation/KLMRegionGrowing/BasicRegionGrowing/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkRegionGrowImageFilter.h" #include "itkCastImageFilter.h" diff --git a/src/Segmentation/LabelVoting/IterativeHoleFilling/Code.cxx b/src/Segmentation/LabelVoting/IterativeHoleFilling/Code.cxx index 9e26e3ed0..c6998921b 100644 --- a/src/Segmentation/LabelVoting/IterativeHoleFilling/Code.cxx +++ b/src/Segmentation/LabelVoting/IterativeHoleFilling/Code.cxx @@ -44,29 +44,23 @@ 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::VotingBinaryIterativeHoleFillingImageFilter; FilterType::InputSizeType radius; radius.Fill(r); FilterType::Pointer filter = FilterType::New(); - filter->SetInput(reader->GetOutput()); + filter->SetInput(input); filter->SetRadius(radius); filter->SetMajorityThreshold(majorityThreshold); filter->SetBackgroundValue(itk::NumericTraits::Zero); filter->SetForegroundValue(itk::NumericTraits::max()); filter->SetMaximumNumberOfIterations(numberOfIterations); - 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/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Code.cxx b/src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Code.cxx index add56d0bc..dab8ae51c 100644 --- a/src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Code.cxx +++ b/src/Segmentation/LevelSets/SegmentWithGeodesicActiveContourLevelSet/Code.cxx @@ -59,18 +59,14 @@ main(int argc, char * argv[]) using OutputPixelType = unsigned char; using OutputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName); + const auto input = itk::ReadImage(inputFileName); using SmoothingFilterType = itk::CurvatureAnisotropicDiffusionImageFilter; SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New(); smoothing->SetTimeStep(0.125); smoothing->SetNumberOfIterations(5); smoothing->SetConductanceParameter(9.0); - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); using GradientFilterType = itk::GradientMagnitudeRecursiveGaussianImageFilter; GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New(); @@ -131,50 +127,33 @@ main(int argc, char * argv[]) CastFilterType::Pointer caster3 = CastFilterType::New(); CastFilterType::Pointer caster4 = CastFilterType::New(); - WriterType::Pointer writer1 = WriterType::New(); - WriterType::Pointer writer2 = WriterType::New(); - WriterType::Pointer writer3 = WriterType::New(); - WriterType::Pointer writer4 = WriterType::New(); - caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName("GeodesicActiveContourImageFilterOutput1.png"); caster1->SetOutputMinimum(itk::NumericTraits::min()); caster1->SetOutputMaximum(itk::NumericTraits::max()); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), "GeodesicActiveContourImageFilterOutput1.png"); caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName("GeodesicActiveContourImageFilterOutput2.png"); caster2->SetOutputMinimum(itk::NumericTraits::min()); caster2->SetOutputMaximum(itk::NumericTraits::max()); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), "GeodesicActiveContourImageFilterOutput2.png"); caster3->SetInput(sigmoid->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName("GeodesicActiveContourImageFilterOutput3.png"); caster3->SetOutputMinimum(itk::NumericTraits::min()); caster3->SetOutputMaximum(itk::NumericTraits::max()); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(), "GeodesicActiveContourImageFilterOutput3.png"); caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName("GeodesicActiveContourImageFilterOutput4.png"); caster4->SetOutputMinimum(itk::NumericTraits::min()); caster4->SetOutputMaximum(itk::NumericTraits::max()); - InputImageType::Pointer inImage = reader->GetOutput(); - fastMarching->SetOutputDirection(inImage->GetDirection()); - fastMarching->SetOutputOrigin(inImage->GetOrigin()); - fastMarching->SetOutputRegion(inImage->GetBufferedRegion()); - fastMarching->SetOutputSpacing(inImage->GetSpacing()); + fastMarching->SetOutputDirection(input->GetDirection()); + fastMarching->SetOutputOrigin(input->GetOrigin()); + fastMarching->SetOutputRegion(input->GetBufferedRegion()); + fastMarching->SetOutputSpacing(input->GetSpacing()); - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputFileName); - writer->SetInput(thresholder->GetOutput()); try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), outputFileName); } catch (itk::ExceptionObject & error) { @@ -191,7 +170,7 @@ main(int argc, char * argv[]) try { - writer4->Update(); + itk::WriteImage(caster4->GetOutput(), "GeodesicActiveContourImageFilterOutput4.png"); } catch (itk::ExceptionObject & error) { @@ -199,14 +178,9 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - using InternalWriterType = itk::ImageFileWriter; - - InternalWriterType::Pointer mapWriter = InternalWriterType::New(); - mapWriter->SetInput(fastMarching->GetOutput()); - mapWriter->SetFileName("GeodesicActiveContourImageFilterOutput4.mha"); try { - mapWriter->Update(); + itk::WriteImage(fastMarching->GetOutput(), "GeodesicActiveContourImageFilterOutput4.mha"); } catch (itk::ExceptionObject & error) { @@ -214,12 +188,9 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - InternalWriterType::Pointer speedWriter = InternalWriterType::New(); - speedWriter->SetInput(sigmoid->GetOutput()); - speedWriter->SetFileName("GeodesicActiveContourImageFilterOutput3.mha"); try { - speedWriter->Update(); + itk::WriteImage(sigmoid->GetOutput(), "GeodesicActiveContourImageFilterOutput3.mha"); } catch (itk::ExceptionObject & error) { @@ -227,12 +198,9 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - InternalWriterType::Pointer gradientWriter = InternalWriterType::New(); - gradientWriter->SetInput(gradientMagnitude->GetOutput()); - gradientWriter->SetFileName("GeodesicActiveContourImageFilterOutput2.mha"); try { - gradientWriter->Update(); + itk::WriteImage(gradientMagnitude->GetOutput(), "GeodesicActiveContourImageFilterOutput2.mha"); } catch (itk::ExceptionObject & error) { diff --git a/src/Segmentation/RegionGrowing/ConnectedComponentsInImage/Code.cxx b/src/Segmentation/RegionGrowing/ConnectedComponentsInImage/Code.cxx index 476e816a7..bb3d98610 100644 --- a/src/Segmentation/RegionGrowing/ConnectedComponentsInImage/Code.cxx +++ b/src/Segmentation/RegionGrowing/ConnectedComponentsInImage/Code.cxx @@ -16,7 +16,6 @@ * *=========================================================================*/ #include "itkImage.h" -#include "itkImageFileWriter.h" #include "itkConnectedThresholdImageFilter.h" #include "itkCastImageFilter.h" diff --git a/src/Segmentation/RegionGrowing/SegmentPixelsWithSimilarStats/Code.cxx b/src/Segmentation/RegionGrowing/SegmentPixelsWithSimilarStats/Code.cxx index 91d5b16d1..d58f2a45e 100644 --- a/src/Segmentation/RegionGrowing/SegmentPixelsWithSimilarStats/Code.cxx +++ b/src/Segmentation/RegionGrowing/SegmentPixelsWithSimilarStats/Code.cxx @@ -39,10 +39,7 @@ main(int argc, char * argv[]) } std::string inputFileName = argv[1]; - using ReaderType = itk::ImageFileReader; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFileName.c_str()); - reader->Update(); + const auto input = itk::ReadImage(inputFileName); using ConfidenceConnectedFilterType = itk::ConfidenceConnectedImageFilter; ConfidenceConnectedFilterType::Pointer confidenceConnectedFilter = ConfidenceConnectedFilterType::New(); @@ -56,11 +53,11 @@ main(int argc, char * argv[]) seed[0] = std::stoi(argv[2]); seed[1] = std::stoi(argv[3]); confidenceConnectedFilter->SetSeed(seed); - confidenceConnectedFilter->SetInput(reader->GetOutput()); + confidenceConnectedFilter->SetInput(input); #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 << "ConfidenceConnected Seed: " << seed[0] << ", " << seed[1]; diff --git a/src/Segmentation/Voronoi/VoronoiDiagram/Code.cxx b/src/Segmentation/Voronoi/VoronoiDiagram/Code.cxx index f016f8f1f..e2b32ed51 100644 --- a/src/Segmentation/Voronoi/VoronoiDiagram/Code.cxx +++ b/src/Segmentation/Voronoi/VoronoiDiagram/Code.cxx @@ -159,11 +159,7 @@ main(int, char *[]) ind[1] = 75; image->SetPixel(ind, 255); - using ImageWriterType = itk::ImageFileWriter; - ImageWriterType::Pointer imageFileWriter = ImageWriterType::New(); - imageFileWriter->SetFileName("image.png"); - imageFileWriter->SetInput(image); - imageFileWriter->Update(); + itk::WriteImage(image, "image.png"); } return EXIT_SUCCESS; diff --git a/src/Segmentation/Watersheds/MorphologicalWatershedSegmentation/Code.cxx b/src/Segmentation/Watersheds/MorphologicalWatershedSegmentation/Code.cxx index 9ca84f1ab..42e58232f 100644 --- a/src/Segmentation/Watersheds/MorphologicalWatershedSegmentation/Code.cxx +++ b/src/Segmentation/Watersheds/MorphologicalWatershedSegmentation/Code.cxx @@ -138,11 +138,7 @@ CreateImage(UnsignedCharImageType::Pointer image) ++imageIterator; } - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - writer->SetFileName("input.png"); - writer->SetInput(image); - writer->Update(); + itk::WriteImage(image, "input.png"); } void @@ -163,9 +159,5 @@ PerformSegmentation(FloatImageType::Pointer image, const float threshold, const std::stringstream ss; ss << "output_" << threshold << "_" << level << ".png"; - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - writer->SetFileName(ss.str()); - writer->SetInput(colormapImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(colormapImageFilter->GetOutput(), ss.str()); } diff --git a/src/Segmentation/Watersheds/SegmentWithWatershedImageFilter/Code.cxx b/src/Segmentation/Watersheds/SegmentWithWatershedImageFilter/Code.cxx index 5a7de7946..5432c2147 100644 --- a/src/Segmentation/Watersheds/SegmentWithWatershedImageFilter/Code.cxx +++ b/src/Segmentation/Watersheds/SegmentWithWatershedImageFilter/Code.cxx @@ -50,14 +50,12 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; using LabeledImageType = itk::Image; - using FileReaderType = itk::ImageFileReader; - FileReaderType::Pointer reader = FileReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); using GradientMagnitudeImageFilterType = itk::GradientMagnitudeImageFilter; GradientMagnitudeImageFilterType::Pointer gradientMagnitudeImageFilter = GradientMagnitudeImageFilterType::New(); - gradientMagnitudeImageFilter->SetInput(reader->GetOutput()); + gradientMagnitudeImageFilter->SetInput(input); gradientMagnitudeImageFilter->Update(); using WatershedFilterType = itk::WatershedImageFilter; @@ -78,11 +76,7 @@ main(int argc, char * argv[]) colormapImageFilter->SetInput(watershed->GetOutput()); colormapImageFilter->Update(); - using FileWriterType = itk::ImageFileWriter; - FileWriterType::Pointer writer = FileWriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(colormapImageFilter->GetOutput()); - writer->Update(); + itk::WriteImage(colormapImageFilter->GetOutput(), argv[2]); return EXIT_SUCCESS; }