From e739d4f49304c5205178b56d1c068da673164ca9 Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Thu, 11 Mar 2021 09:37:00 -0600 Subject: [PATCH] ENH: Implement ITK's WriteImage functions --- .../ThinImage/Code.cxx | 16 ++---------- .../Code.cxx | 25 ++++--------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx b/src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.cxx index 92709467b..3ce372139 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); @@ -44,7 +42,7 @@ main(int argc, char * argv[]) else { CreateImage(image); - WriteImage(image, "input.png"); + itk::WriteImage(image, "input.png"); } using BinaryThinningImageFilterType = itk::BinaryThinningImageFilter; @@ -60,7 +58,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 +91,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/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx b/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx index 72efcfcd6..09cb09742 100644 --- a/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx +++ b/src/Filtering/Convolution/NormalizedCorrelationOfMaskedImage/Code.cxx @@ -40,10 +40,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 +47,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 +55,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 +68,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 +97,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 +105,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 +206,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(); -}