From 7b17773aa24a3e90c0ecc8615e61f67b9b50f852 Mon Sep 17 00:00:00 2001 From: Sadhana Ravikumar Date: Fri, 24 Jan 2025 18:18:14 -0500 Subject: [PATCH] STYLE: Use itk::ReadImage/itk::WriteImage in Examples/Registration --- .../MultiResImageRegistration1.cxx | 40 +-- .../MultiResImageRegistration2.cxx | 36 +-- .../MultiResImageRegistration3.cxx | 42 +-- .../MultiStageImageRegistration1.cxx | 38 +-- .../MultiStageImageRegistration2.cxx | 37 +-- .../RegistrationITKv4/ThinPlateSplineWarp.cxx | 27 +- .../CannySegmentationLevelSetImageFilter.cxx | 2 +- Examples/Segmentation/ConfidenceConnected.cxx | 2 +- .../ConnectedThresholdImageFilter.cxx | 2 +- .../CurvesLevelSetImageFilter.cxx | 2 +- .../Segmentation/FastMarchingImageFilter.cxx | 6 +- .../GeodesicActiveContourImageFilter.cxx | 2 +- ...veContourShapePriorLevelSetImageFilter.cxx | 256 +++++++++--------- .../Segmentation/GibbsPriorImageFilter1.cxx | 46 ++-- .../HoughTransform2DCirclesImageFilter.cxx | 4 +- .../HoughTransform2DLinesImageFilter.cxx | 4 +- .../IsolatedConnectedImageFilter.cxx | 4 +- ...placianSegmentationLevelSetImageFilter.cxx | 2 +- .../NeighborhoodConnectedImageFilter.cxx | 2 +- .../RelabelComponentImageFilter.cxx | 20 +- .../ShapeDetectionLevelSetFilter.cxx | 27 +- ...resholdSegmentationLevelSetImageFilter.cxx | 20 +- .../VectorConfidenceConnected.cxx | 4 +- .../Segmentation/WatershedSegmentation1.cxx | 2 +- .../Segmentation/WatershedSegmentation2.cxx | 2 +- .../BoundingBoxFromImageMaskSpatialObject.cxx | 2 +- Examples/Statistics/BayesianClassifier.cxx | 2 +- .../BayesianClassifierInitializer.cxx | 4 +- Examples/Statistics/ImageEntropy1.cxx | 2 +- Examples/Statistics/ImageHistogram1.cxx | 2 +- Examples/Statistics/ImageHistogram2.cxx | 2 +- Examples/Statistics/ImageHistogram3.cxx | 2 +- Examples/Statistics/ImageHistogram4.cxx | 2 +- .../ScalarImageKmeansClassifier.cxx | 2 +- .../ScalarImageKmeansModelEstimator.cxx | 1 + 35 files changed, 266 insertions(+), 384 deletions(-) diff --git a/Examples/RegistrationITKv4/MultiResImageRegistration1.cxx b/Examples/RegistrationITKv4/MultiResImageRegistration1.cxx index 8d4fd87b165..be24f9fa311 100644 --- a/Examples/RegistrationITKv4/MultiResImageRegistration1.cxx +++ b/Examples/RegistrationITKv4/MultiResImageRegistration1.cxx @@ -377,17 +377,11 @@ main(int argc, const char * argv[]) registration->SetOptimizer(optimizer); registration->SetMetric(metric); - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; + const auto fixedImage = itk::ReadImage(fixedImageFile); + const auto movingImage = itk::ReadImage(movingImageFile); - auto fixedImageReader = FixedImageReaderType::New(); - auto movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(fixedImageFile); - movingImageReader->SetFileName(movingImageFile); - - registration->SetFixedImage(fixedImageReader->GetOutput()); - registration->SetMovingImage(movingImageReader->GetOutput()); + registration->SetFixedImage(fixedImage); + registration->SetMovingImage(movingImage); using ParametersType = OptimizerType::ParametersType; @@ -568,10 +562,7 @@ main(int argc, const char * argv[]) auto resample = ResampleFilterType::New(); resample->SetTransform(transform); - resample->SetInput(movingImageReader->GetOutput()); - - const FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); - + resample->SetInput(movingImage); resample->SetSize(fixedImage->GetLargestPossibleRegion().GetSize()); resample->SetOutputOrigin(fixedImage->GetOrigin()); @@ -586,20 +577,10 @@ main(int argc, const char * argv[]) using CastFilterType = itk::CastImageFilter; - - using WriterType = itk::ImageFileWriter; - - - auto writer = WriterType::New(); auto caster = CastFilterType::New(); - - - writer->SetFileName(outImagefile); - - caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + + itk::WriteImage(caster->GetOutput(), outImagefile); // // Generate checkerboards before and after registration @@ -612,7 +593,6 @@ main(int argc, const char * argv[]) checker->SetInput2(resample->GetOutput()); caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); resample->SetDefaultPixelValue(0); @@ -627,8 +607,7 @@ main(int argc, const char * argv[]) } if (checkerBoardBefore != std::string("")) { - writer->SetFileName(checkerBoardBefore); - writer->Update(); + itk::WriteImage(caster->GetOutput(), checkerBoardBefore); } @@ -636,8 +615,7 @@ main(int argc, const char * argv[]) resample->SetTransform(transform); if (checkerBoardAfter != std::string("")) { - writer->SetFileName(checkerBoardAfter); - writer->Update(); + itk::WriteImage(caster->GetOutput(), checkerBoardAfter); } // Software Guide : BeginLatex diff --git a/Examples/RegistrationITKv4/MultiResImageRegistration2.cxx b/Examples/RegistrationITKv4/MultiResImageRegistration2.cxx index b5d9db1ed28..83c455a761f 100644 --- a/Examples/RegistrationITKv4/MultiResImageRegistration2.cxx +++ b/Examples/RegistrationITKv4/MultiResImageRegistration2.cxx @@ -244,14 +244,8 @@ main(int argc, char * argv[]) registration->SetTransform(transform); // Software Guide : EndCodeSnippet - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; - - auto fixedImageReader = FixedImageReaderType::New(); - auto movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(argv[1]); - movingImageReader->SetFileName(argv[2]); + const auto fixedImage = itk::ReadImage(argv[1]); + const auto movingImage = itk::ReadImage(argv[2]); using FixedCastFilterType = itk::CastImageFilter; @@ -260,8 +254,8 @@ main(int argc, char * argv[]) auto fixedCaster = FixedCastFilterType::New(); auto movingCaster = MovingCastFilterType::New(); - fixedCaster->SetInput(fixedImageReader->GetOutput()); - movingCaster->SetInput(movingImageReader->GetOutput()); + fixedCaster->SetInput(fixedImage); + movingCaster->SetInput(movingImage); registration->SetFixedImage(fixedCaster->GetOutput()); registration->SetMovingImage(movingCaster->GetOutput()); @@ -289,8 +283,8 @@ main(int argc, char * argv[]) MovingImageType>; auto initializer = TransformInitializerType::New(); initializer->SetTransform(transform); - initializer->SetFixedImage(fixedImageReader->GetOutput()); - initializer->SetMovingImage(movingImageReader->GetOutput()); + initializer->SetFixedImage(fixedImage); + initializer->SetMovingImage(movingImage); initializer->MomentsOn(); initializer->InitializeTransform(); registration->SetInitialTransformParameters(transform->GetParameters()); @@ -533,9 +527,8 @@ main(int argc, char * argv[]) auto resample = ResampleFilterType::New(); resample->SetTransform(finalTransform); - resample->SetInput(movingImageReader->GetOutput()); + resample->SetInput(movingImage); - const FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); PixelType backgroundGrayLevel = 100; if (argc > 4) @@ -553,16 +546,10 @@ main(int argc, char * argv[]) using OutputImageType = itk::Image; using CastFilterType = itk::CastImageFilter; - using WriterType = itk::ImageFileWriter; - - auto writer = WriterType::New(); auto caster = CastFilterType::New(); - writer->SetFileName(argv[3]); - caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[3]); // Software Guide : BeginLatex // @@ -613,7 +600,6 @@ main(int argc, char * argv[]) checker->SetInput2(resample->GetOutput()); caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); resample->SetDefaultPixelValue(0); @@ -625,16 +611,14 @@ main(int argc, char * argv[]) if (argc > 5) { - writer->SetFileName(argv[5]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[5]); } // After registration resample->SetTransform(finalTransform); if (argc > 6) { - writer->SetFileName(argv[6]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[6]); } return EXIT_SUCCESS; diff --git a/Examples/RegistrationITKv4/MultiResImageRegistration3.cxx b/Examples/RegistrationITKv4/MultiResImageRegistration3.cxx index 531c94d9a16..19a7d47cff8 100644 --- a/Examples/RegistrationITKv4/MultiResImageRegistration3.cxx +++ b/Examples/RegistrationITKv4/MultiResImageRegistration3.cxx @@ -197,16 +197,10 @@ main(int argc, char * argv[]) registration->SetFixedImagePyramid(fixedImagePyramid); registration->SetMovingImagePyramid(movingImagePyramid); - - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; - - auto fixedImageReader = FixedImageReaderType::New(); - auto movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(argv[1]); - movingImageReader->SetFileName(argv[2]); - + const FixedImageType::Pointer fixedImage = + itk::ReadImage(argv[1]); + const MovingImageType::Pointer movingImage = + itk::ReadImage(argv[2]); using FixedCastFilterType = itk::CastImageFilter; @@ -216,8 +210,8 @@ main(int argc, char * argv[]) auto fixedCaster = FixedCastFilterType::New(); auto movingCaster = MovingCastFilterType::New(); - fixedCaster->SetInput(fixedImageReader->GetOutput()); - movingCaster->SetInput(movingImageReader->GetOutput()); + fixedCaster->SetInput(fixedImage); + movingCaster->SetInput(movingImage); registration->SetFixedImage(fixedCaster->GetOutput()); registration->SetMovingImage(movingCaster->GetOutput()); @@ -329,9 +323,7 @@ main(int argc, char * argv[]) auto resample = ResampleFilterType::New(); resample->SetTransform(finalTransform); - resample->SetInput(movingImageReader->GetOutput()); - - const FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); + resample->SetInput(movingImage); PixelType backgroundGrayLevel = 100; if (argc > 4) @@ -352,20 +344,9 @@ main(int argc, char * argv[]) using CastFilterType = itk::CastImageFilter; - - using WriterType = itk::ImageFileWriter; - - - auto writer = WriterType::New(); auto caster = CastFilterType::New(); - - - writer->SetFileName(argv[3]); - - caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[3]); // // Generate checkerboards before and after registration @@ -378,7 +359,6 @@ main(int argc, char * argv[]) checker->SetInput2(resample->GetOutput()); caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); resample->SetDefaultPixelValue(0); @@ -389,8 +369,7 @@ main(int argc, char * argv[]) if (argc > 5) { - writer->SetFileName(argv[5]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[5]); } @@ -398,8 +377,7 @@ main(int argc, char * argv[]) resample->SetTransform(finalTransform); if (argc > 6) { - writer->SetFileName(argv[6]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[6]); } return EXIT_SUCCESS; diff --git a/Examples/RegistrationITKv4/MultiStageImageRegistration1.cxx b/Examples/RegistrationITKv4/MultiStageImageRegistration1.cxx index 2b9db9b7f2c..53fc8010c42 100644 --- a/Examples/RegistrationITKv4/MultiStageImageRegistration1.cxx +++ b/Examples/RegistrationITKv4/MultiStageImageRegistration1.cxx @@ -314,17 +314,11 @@ main(int argc, char * argv[]) compositeTransform->AddTransform(movingInitTx); // Software Guide : EndCodeSnippet - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; + const auto fixedImage = itk::ReadImage(argv[1]); + const auto movingImage = itk::ReadImage(argv[2]); - auto fixedImageReader = FixedImageReaderType::New(); - auto movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(argv[1]); - movingImageReader->SetFileName(argv[2]); - - transRegistration->SetFixedImage(fixedImageReader->GetOutput()); - transRegistration->SetMovingImage(movingImageReader->GetOutput()); + transRegistration->SetFixedImage(fixedImage); + transRegistration->SetMovingImage(movingImage); transRegistration->SetObjectName("TranslationRegistration"); // Software Guide : BeginLatex @@ -478,8 +472,8 @@ main(int argc, char * argv[]) affineRegistration->SetMovingInitialTransform(compositeTransform); // Software Guide : EndCodeSnippet - affineRegistration->SetFixedImage(fixedImageReader->GetOutput()); - affineRegistration->SetMovingImage(movingImageReader->GetOutput()); + affineRegistration->SetFixedImage(fixedImage); + affineRegistration->SetMovingImage(movingImage); affineRegistration->SetObjectName("AffineRegistration"); affineMetric->SetNumberOfHistogramBins(24); @@ -533,8 +527,6 @@ main(int argc, char * argv[]) using RegionType = FixedImageType::RegionType; using SizeType = FixedImageType::SizeType; - const FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); - const SpacingType fixedSpacing = fixedImage->GetSpacing(); const OriginType fixedOrigin = fixedImage->GetOrigin(); const RegionType fixedRegion = fixedImage->GetLargestPossibleRegion(); @@ -881,7 +873,7 @@ main(int argc, char * argv[]) auto resample = ResampleFilterType::New(); resample->SetTransform(compositeTransform); - resample->SetInput(movingImageReader->GetOutput()); + resample->SetInput(movingImage); PixelType backgroundGrayLevel = 100; if (argc > 4) @@ -899,16 +891,10 @@ main(int argc, char * argv[]) using OutputImageType = itk::Image; using CastFilterType = itk::CastImageFilter; - using WriterType = itk::ImageFileWriter; - - auto writer = WriterType::New(); auto caster = CastFilterType::New(); - writer->SetFileName(argv[3]); - caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[3]); // Software Guide : BeginLatex // @@ -937,9 +923,7 @@ main(int argc, char * argv[]) checker->SetInput1(fixedImage); checker->SetInput2(resample->GetOutput()); - caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); resample->SetDefaultPixelValue(0); @@ -961,16 +945,14 @@ main(int argc, char * argv[]) if (argc > 5) { - writer->SetFileName(argv[5]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[5]); } // After registration resample->SetTransform(compositeTransform); if (argc > 6) { - writer->SetFileName(argv[6]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[6]); } return EXIT_SUCCESS; diff --git a/Examples/RegistrationITKv4/MultiStageImageRegistration2.cxx b/Examples/RegistrationITKv4/MultiStageImageRegistration2.cxx index ceb64cef166..5f0ec379302 100644 --- a/Examples/RegistrationITKv4/MultiStageImageRegistration2.cxx +++ b/Examples/RegistrationITKv4/MultiStageImageRegistration2.cxx @@ -254,17 +254,11 @@ main(int argc, char * argv[]) // // Software Guide : EndLatex - using FixedImageReaderType = itk::ImageFileReader; - using MovingImageReaderType = itk::ImageFileReader; + const auto fixedImage = itk::ReadImage(argv[1]); + const auto movingImage = itk::ReadImage(argv[2]); - auto fixedImageReader = FixedImageReaderType::New(); - auto movingImageReader = MovingImageReaderType::New(); - - fixedImageReader->SetFileName(argv[1]); - movingImageReader->SetFileName(argv[2]); - - transRegistration->SetFixedImage(fixedImageReader->GetOutput()); - transRegistration->SetMovingImage(movingImageReader->GetOutput()); + transRegistration->SetFixedImage(fixedImage); + transRegistration->SetMovingImage(movingImage); transRegistration->SetObjectName("TranslationRegistration"); // Software Guide : BeginLatex @@ -368,8 +362,6 @@ main(int argc, char * argv[]) affineMetric->SetNumberOfHistogramBins(std::stoi(argv[7])); } - fixedImageReader->Update(); - const FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput(); // Software Guide : BeginCodeSnippet using FixedImageCalculatorType = @@ -406,8 +398,8 @@ main(int argc, char * argv[]) affineRegistration->InPlaceOn(); // Software Guide : EndCodeSnippet - affineRegistration->SetFixedImage(fixedImageReader->GetOutput()); - affineRegistration->SetMovingImage(movingImageReader->GetOutput()); + affineRegistration->SetFixedImage(fixedImage); + affineRegistration->SetMovingImage(movingImage); affineRegistration->SetObjectName("AffineRegistration"); // Software Guide : BeginLatex @@ -597,7 +589,7 @@ main(int argc, char * argv[]) auto resample = ResampleFilterType::New(); resample->SetTransform(compositeTransform); - resample->SetInput(movingImageReader->GetOutput()); + resample->SetInput(movingImage); PixelType backgroundGrayLevel = 100; if (argc > 4) @@ -615,16 +607,10 @@ main(int argc, char * argv[]) using OutputImageType = itk::Image; using CastFilterType = itk::CastImageFilter; - using WriterType = itk::ImageFileWriter; - - auto writer = WriterType::New(); auto caster = CastFilterType::New(); - writer->SetFileName(argv[3]); - caster->SetInput(resample->GetOutput()); - writer->SetInput(caster->GetOutput()); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[3]); // Software Guide : BeginLatex // @@ -657,7 +643,6 @@ main(int argc, char * argv[]) checker->SetInput2(resample->GetOutput()); caster->SetInput(checker->GetOutput()); - writer->SetInput(caster->GetOutput()); resample->SetDefaultPixelValue(0); @@ -679,16 +664,14 @@ main(int argc, char * argv[]) if (argc > 5) { - writer->SetFileName(argv[5]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[5]); } // After registration resample->SetTransform(compositeTransform); if (argc > 6) { - writer->SetFileName(argv[6]); - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[6]); } return EXIT_SUCCESS; diff --git a/Examples/RegistrationITKv4/ThinPlateSplineWarp.cxx b/Examples/RegistrationITKv4/ThinPlateSplineWarp.cxx index a2a5db56482..0ffa5e33e4f 100644 --- a/Examples/RegistrationITKv4/ThinPlateSplineWarp.cxx +++ b/Examples/RegistrationITKv4/ThinPlateSplineWarp.cxx @@ -58,11 +58,8 @@ main(int argc, char * argv[]) using PixelType = unsigned char; using InputImageType = itk::Image; - using ReaderType = itk::ImageFileReader; - using DeformedImageWriterType = itk::ImageFileWriter; using FieldVectorType = itk::Vector; using DisplacementFieldType = itk::Image; - using FieldWriterType = itk::ImageFileWriter; using CoordinateRepType = double; using TransformType = itk::ThinPlateSplineKernelTransform; @@ -74,12 +71,10 @@ main(int argc, char * argv[]) using InterpolatorType = itk::LinearInterpolateImageFunction; - auto reader = ReaderType::New(); - reader->SetFileName(argv[2]); - + InputImageType::ConstPointer inputImage; try { - reader->Update(); + inputImage = itk::ReadImage(argv[2]); } catch (const itk::ExceptionObject & excp) { @@ -141,9 +136,8 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Set the resampler params - const InputImageType::ConstPointer inputImage = reader->GetOutput(); - auto resampler = ResamplerType::New(); - auto interpolator = InterpolatorType::New(); + auto resampler = ResamplerType::New(); + auto interpolator = InterpolatorType::New(); resampler->SetInterpolator(interpolator); const InputImageType::SpacingType spacing = inputImage->GetSpacing(); const InputImageType::PointType origin = inputImage->GetOrigin(); @@ -160,16 +154,12 @@ main(int argc, char * argv[]) // Software Guide : EndCodeSnippet resampler->SetOutputStartIndex(region.GetIndex()); - resampler->SetInput(reader->GetOutput()); + resampler->SetInput(inputImage); // Set and write deformed image - auto deformedImageWriter = DeformedImageWriterType::New(); - deformedImageWriter->SetInput(resampler->GetOutput()); - deformedImageWriter->SetFileName(argv[3]); - try { - deformedImageWriter->Update(); + itk::WriteImage(resampler->GetOutput(), argv[3]); } catch (const itk::ExceptionObject & excp) { @@ -216,12 +206,9 @@ main(int argc, char * argv[]) } // Write computed deformation field - auto fieldWriter = FieldWriterType::New(); - fieldWriter->SetFileName(argv[4]); - fieldWriter->SetInput(field); try { - fieldWriter->Update(); + itk::WriteImage(field, argv[4]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx b/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx index aee6db09332..5b476f3cf66 100644 --- a/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx @@ -258,7 +258,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(), argv[3]) + itk::WriteImage(thresholder->GetOutput(), argv[3]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/ConfidenceConnected.cxx b/Examples/Segmentation/ConfidenceConnected.cxx index 4b2ac8049e0..b65753018af 100644 --- a/Examples/Segmentation/ConfidenceConnected.cxx +++ b/Examples/Segmentation/ConfidenceConnected.cxx @@ -328,7 +328,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(caster->GetOutput(), argv[2]) + itk::WriteImage(caster->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/ConnectedThresholdImageFilter.cxx b/Examples/Segmentation/ConnectedThresholdImageFilter.cxx index 972efb7b792..efc9e16d077 100644 --- a/Examples/Segmentation/ConnectedThresholdImageFilter.cxx +++ b/Examples/Segmentation/ConnectedThresholdImageFilter.cxx @@ -193,7 +193,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); connectedThreshold->SetInput(smoothing->GetOutput()); caster->SetInput(connectedThreshold->GetOutput()); // Software Guide : EndCodeSnippet diff --git a/Examples/Segmentation/CurvesLevelSetImageFilter.cxx b/Examples/Segmentation/CurvesLevelSetImageFilter.cxx index 390027ed2c2..d1e2b7082e6 100644 --- a/Examples/Segmentation/CurvesLevelSetImageFilter.cxx +++ b/Examples/Segmentation/CurvesLevelSetImageFilter.cxx @@ -430,7 +430,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(), argv[2]) + itk::WriteImage(thresholder->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/FastMarchingImageFilter.cxx b/Examples/Segmentation/FastMarchingImageFilter.cxx index 788d719c49b..eadf41ad8bb 100644 --- a/Examples/Segmentation/FastMarchingImageFilter.cxx +++ b/Examples/Segmentation/FastMarchingImageFilter.cxx @@ -576,7 +576,7 @@ main(int argc, char * argv[]) caster1->SetInput(smoothing->GetOutput()); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - itk::WriteImage(caster1->GetOutput(), argv[10]) + itk::WriteImage(caster1->GetOutput(), argv[10]); } catch (const itk::ExceptionObject & err) { @@ -663,7 +663,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(),argv[2])) + itk::WriteImage(thresholder->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { @@ -679,7 +679,7 @@ main(int argc, char * argv[]) caster4->SetInput(fastMarching->GetOutput()); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); - itk::WriteImage(caster4->GetOutput(), "FastMarchingFilterOutput4.png") + itk::WriteImage(caster4->GetOutput(), "FastMarchingFilterOutput4.png"); } catch (const itk::ExceptionObject & err) { diff --git a/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx b/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx index ddc0a58d30b..39dccd50361 100644 --- a/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx +++ b/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx @@ -456,7 +456,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(), argv[2]) + itk::WriteImage(thresholder->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx b/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx index 53d611942f0..c07c6776f34 100644 --- a/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx +++ b/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx @@ -612,9 +612,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - auto meanShapeReader = ReaderType::New(); - meanShapeReader->SetFileName(argv[13]); - meanShapeReader->Update(); + const auto meanShapeImage = itk::ReadImage(argv[13]); std::vector shapeModeImages(numberOfPCAModes); @@ -628,13 +626,11 @@ main(int argc, char * argv[]) for (unsigned int k = 0; k < numberOfPCAModes; ++k) { - auto shapeModeReader = ReaderType::New(); - shapeModeReader->SetFileName(shapeModeFileNames[k].c_str()); - shapeModeReader->Update(); - shapeModeImages[k] = shapeModeReader->GetOutput(); + shapeModeImages[k] = + itk::ReadImage(shapeModeFileNames[k].c_str()); } - shape->SetMeanImage(meanShapeReader->GetOutput()); + shape->SetMeanImage(meanShapeImage); shape->SetPrincipalComponentImages(shapeModeImages); // Software Guide : EndCodeSnippet @@ -878,7 +874,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(), argv[2]) + itk::WriteImage(thresholder->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { @@ -945,128 +941,128 @@ main(int argc, char * argv[]) thresholder->SetInput(evaluator->GetOutput()); itk::WriteImage(thresholder->GetOutput(), - "GeodesicActiveContourShapePriorImageFilterOutput5.png") + "GeodesicActiveContourShapePriorImageFilterOutput5.png"); - shape->SetParameters(geodesicActiveContour->GetCurrentParameters()); + shape->SetParameters(geodesicActiveContour->GetCurrentParameters()); evaluator->Modified(); itk::WriteImage(thresholder->GetOutput(), - "GeodesicActiveContourShapePriorImageFilterOutput6.png") - - - // Software Guide : BeginLatex - // - // Deviating from previous examples, we will demonstrate this example - // using - // \code{BrainMidSagittalSlice.png} - // (Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput}, - // left) from the \code{Examples/Data} directory. The aim here is to - // segment the corpus callosum from the image using a shape model defined - // by \code{CorpusCallosumMeanShape.mha} and the first three principal - // components \code{CorpusCallosumMode0.mha}, - // \code{CorpusCallosumMode1.mha} and \code{CorpusCallosumMode12.mha}. As - // shown in Figure~\ref{fig:CorpusCallosumPCAModes}, the first mode - // captures scaling, the second mode captures the shifting of mass - // between the rostrum and the splenium and the third mode captures the - // degree of curvature. Segmentation results with and without shape - // guidance are shown in - // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2}. - // - // - // \begin{figure} \center - // \includegraphics[width=0.30\textwidth]{BrainMidSagittalSlice} - // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput5} - // \itkcaption[GeodesicActiveContourShapePriorImageFilter input image and - // initial model]{ The input image to the - // GeodesicActiveContourShapePriorLevelSetImageFilter is a synthesized - // MR-T1 mid-sagittal slice ($217 \times 180$ pixels, $1 \times 1$ mm - // spacing) of the brain (left) and the initial best-fit shape (right) - // chosen to roughly overlap the corpus callosum in the image to be - // segmented.} - // - // \label{fig:GeodesicActiveContourShapePriorImageFilterOutput} - // \end{figure} - // - // - // \begin{figure} - // \center - // \begin{tabular}{cccc} - // & $-3\sigma$ & mean & $+3\sigma$ \\ mode 0: & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus0} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus0} - // \\ mode 1: & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus1} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus1} - // \\ mode 2: & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus2} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & - // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus2} - // \\ \end{tabular} - // \itkcaption[Corpus callosum PCA modes]{First three PCA - // modes of a low-resolution - // ($58 \times 31$ pixels, $2 \times 2$ mm spacing) corpus callosum model - // used in the shape guided geodesic active contours example.} - // - // \label{fig:CorpusCallosumPCAModes} - // \end{figure} - // - // A sigma value of $1.0$ was used to compute the image gradient and the - // propagation and shape prior scaling are respectively set to $0.5$ and - // $0.02$. An initial level set was created by placing one seed point in - // the rostrum $(60,102)$, one in the splenium $(120, 85)$ and one - // centrally in the body $(88,83)$ of the corpus callosum with - // an initial radius of $6$ pixels at each seed position. - // The best-fit shape was initially placed with a translation of - // $(10,0)$mm so that it roughly overlapped - // the corpus callosum in the image as shown in - // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput} - // (right). - // - // From - // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2} it - // can be observed that without shape guidance (left), segmentation using - // geodesic active contour leaks in the regions where the corpus callosum - // blends into the surrounding brain tissues. With shape guidance - // (center), the segmentation is constrained by the global shape model to - // prevent leaking. - // - // The final best-fit shape parameters after the segmentation process is: - // - // \begin{verbatim} - // Parameters: [-0.384988, -0.578738, 0.557793, - // 0.275202, 16.9992, 4.73473] - // \end{verbatim} - // - // and is shown in - // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2} - // (right). Note that a $0.28$ radian ($15.8$ degree) rotation has been - // introduced to match the model to the corpus callosum in the image. - // Additionally, a negative weight for the first mode shrinks the size - // relative to the mean shape. A negative weight for the second mode - // shifts the mass to splenium, and a positive weight for the third mode - // increases the curvature. It can also be observed that the final - // segmentation is a combination of the best-fit shape with additional - // local deformation. The combination of both global and local shape - // allows the segmentation to capture fine details not represented in the - // shape model. - // - // - // \begin{figure} \center - // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput1} - // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput2} - // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput6} - // \itkcaption[GeodesicActiveContourShapePriorImageFilter - // segmentations]{Corpus callosum segmentation using geodesic active - // contours without (left) and with (center) shape guidance. The image on - // the right represents the best-fit shape at the end of the segmentation - // process.} - // - // \label{fig:GeodesicActiveContourShapePriorImageFilterOutput2} - // \end{figure} - // - // - // Software Guide : EndLatex - - return EXIT_SUCCESS; + "GeodesicActiveContourShapePriorImageFilterOutput6.png"); + + + // Software Guide : BeginLatex + // + // Deviating from previous examples, we will demonstrate this example + // using + // \code{BrainMidSagittalSlice.png} + // (Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput}, + // left) from the \code{Examples/Data} directory. The aim here is to + // segment the corpus callosum from the image using a shape model defined + // by \code{CorpusCallosumMeanShape.mha} and the first three principal + // components \code{CorpusCallosumMode0.mha}, + // \code{CorpusCallosumMode1.mha} and \code{CorpusCallosumMode12.mha}. As + // shown in Figure~\ref{fig:CorpusCallosumPCAModes}, the first mode + // captures scaling, the second mode captures the shifting of mass + // between the rostrum and the splenium and the third mode captures the + // degree of curvature. Segmentation results with and without shape + // guidance are shown in + // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2}. + // + // + // \begin{figure} \center + // \includegraphics[width=0.30\textwidth]{BrainMidSagittalSlice} + // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput5} + // \itkcaption[GeodesicActiveContourShapePriorImageFilter input image and + // initial model]{ The input image to the + // GeodesicActiveContourShapePriorLevelSetImageFilter is a synthesized + // MR-T1 mid-sagittal slice ($217 \times 180$ pixels, $1 \times 1$ mm + // spacing) of the brain (left) and the initial best-fit shape (right) + // chosen to roughly overlap the corpus callosum in the image to be + // segmented.} + // + // \label{fig:GeodesicActiveContourShapePriorImageFilterOutput} + // \end{figure} + // + // + // \begin{figure} + // \center + // \begin{tabular}{cccc} + // & $-3\sigma$ & mean & $+3\sigma$ \\ mode 0: & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus0} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus0} + // \\ mode 1: & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus1} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus1} + // \\ mode 2: & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModeMinus2} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumMeanShape} & + // \includegraphics[width=0.10\textwidth]{CorpusCallosumModePlus2} + // \\ \end{tabular} + // \itkcaption[Corpus callosum PCA modes]{First three PCA + // modes of a low-resolution + // ($58 \times 31$ pixels, $2 \times 2$ mm spacing) corpus callosum model + // used in the shape guided geodesic active contours example.} + // + // \label{fig:CorpusCallosumPCAModes} + // \end{figure} + // + // A sigma value of $1.0$ was used to compute the image gradient and the + // propagation and shape prior scaling are respectively set to $0.5$ and + // $0.02$. An initial level set was created by placing one seed point in + // the rostrum $(60,102)$, one in the splenium $(120, 85)$ and one + // centrally in the body $(88,83)$ of the corpus callosum with + // an initial radius of $6$ pixels at each seed position. + // The best-fit shape was initially placed with a translation of + // $(10,0)$mm so that it roughly overlapped + // the corpus callosum in the image as shown in + // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput} + // (right). + // + // From + // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2} it + // can be observed that without shape guidance (left), segmentation using + // geodesic active contour leaks in the regions where the corpus callosum + // blends into the surrounding brain tissues. With shape guidance + // (center), the segmentation is constrained by the global shape model to + // prevent leaking. + // + // The final best-fit shape parameters after the segmentation process is: + // + // \begin{verbatim} + // Parameters: [-0.384988, -0.578738, 0.557793, + // 0.275202, 16.9992, 4.73473] + // \end{verbatim} + // + // and is shown in + // Figure~\ref{fig:GeodesicActiveContourShapePriorImageFilterOutput2} + // (right). Note that a $0.28$ radian ($15.8$ degree) rotation has been + // introduced to match the model to the corpus callosum in the image. + // Additionally, a negative weight for the first mode shrinks the size + // relative to the mean shape. A negative weight for the second mode + // shifts the mass to splenium, and a positive weight for the third mode + // increases the curvature. It can also be observed that the final + // segmentation is a combination of the best-fit shape with additional + // local deformation. The combination of both global and local shape + // allows the segmentation to capture fine details not represented in the + // shape model. + // + // + // \begin{figure} \center + // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput1} + // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput2} + // \includegraphics[width=0.30\textwidth]{GeodesicActiveContourShapePriorImageFilterOutput6} + // \itkcaption[GeodesicActiveContourShapePriorImageFilter + // segmentations]{Corpus callosum segmentation using geodesic active + // contours without (left) and with (center) shape guidance. The image on + // the right represents the best-fit shape at the end of the segmentation + // process.} + // + // \label{fig:GeodesicActiveContourShapePriorImageFilterOutput2} + // \end{figure} + // + // + // Software Guide : EndLatex + + return EXIT_SUCCESS; } diff --git a/Examples/Segmentation/GibbsPriorImageFilter1.cxx b/Examples/Segmentation/GibbsPriorImageFilter1.cxx index 6692256de1f..4a3d4e29a29 100644 --- a/Examples/Segmentation/GibbsPriorImageFilter1.cxx +++ b/Examples/Segmentation/GibbsPriorImageFilter1.cxx @@ -283,27 +283,27 @@ main(int argc, char * argv[]) std::cout << "applyGibbsImageFilter: " << applyGibbsImageFilter; - itk::WriteImage(applyGibbsImageFilter->GetOutput(), argv[3]) - - // Software Guide : BeginLatex - // - // We execute this program on the image \code{brainweb89.png}. The - // following parameters are passed to the command line: - // - // \small - // \begin{verbatim} - // GibbsGuide.exe brainweb89.png brainweb89_train.png brainweb_gp.png - // \end{verbatim} - // \normalsize - // - // \code{brainweb89train} is a training image that helps to estimate the - // object statistics. - // - // Note that in order to successfully segment other images, one has to - // create suitable training images for them. We can also segment color - // (RGB) and other multi-channel images. - // - // Software Guide : EndLatex - - return EXIT_SUCCESS; + itk::WriteImage(applyGibbsImageFilter->GetOutput(), argv[3]); + + // Software Guide : BeginLatex + // + // We execute this program on the image \code{brainweb89.png}. The + // following parameters are passed to the command line: + // + // \small + // \begin{verbatim} + // GibbsGuide.exe brainweb89.png brainweb89_train.png brainweb_gp.png + // \end{verbatim} + // \normalsize + // + // \code{brainweb89train} is a training image that helps to estimate the + // object statistics. + // + // Note that in order to successfully segment other images, one has to + // create suitable training images for them. We can also segment color + // (RGB) and other multi-channel images. + // + // Software Guide : EndLatex + + return EXIT_SUCCESS; } diff --git a/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx b/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx index 8e241dc6eaa..d3d20a5cfee 100644 --- a/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx +++ b/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx @@ -88,7 +88,7 @@ main(int argc, char * argv[]) // // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ImageType::Pointer localImage; + ImageType::Pointer localImage; try { localImage = itk::ReadImage(argv[1]); @@ -265,7 +265,7 @@ main(int argc, char * argv[]) try { - itk::WriteImage(localOutputImage, argv[2]) + itk::WriteImage(localOutputImage, argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx b/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx index 8acfaddd37a..54ebd06a480 100644 --- a/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx +++ b/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx @@ -82,7 +82,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ImageType::Pointer localImage; + ImageType::Pointer localImage; try { localImage = itk::ReadImage(argv[1]); @@ -140,7 +140,7 @@ main(int argc, char * argv[]) constexpr unsigned char threshBelow = 0; constexpr unsigned char threshAbove = 255; threshFilter->ThresholdOutside(threshBelow, threshAbove); - threshlocalImageFilter->Update(); + threshFilter->Update(); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex diff --git a/Examples/Segmentation/IsolatedConnectedImageFilter.cxx b/Examples/Segmentation/IsolatedConnectedImageFilter.cxx index 23f44639a7c..aa78cc972f8 100644 --- a/Examples/Segmentation/IsolatedConnectedImageFilter.cxx +++ b/Examples/Segmentation/IsolatedConnectedImageFilter.cxx @@ -130,7 +130,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); isolatedConnected->SetInput(smoothing->GetOutput()); caster->SetInput(isolatedConnected->GetOutput()); // Software Guide : EndCodeSnippet @@ -199,7 +199,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(caster->GetOutput(), argv[2]) + itk::WriteImage(caster->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx b/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx index 0e79920e792..423fc474c5a 100644 --- a/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx @@ -232,7 +232,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(thresholder->GetOutput(), argv[3]) + itk::WriteImage(thresholder->GetOutput(), argv[3]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx b/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx index 3f6dd4afce2..c26049fff24 100644 --- a/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx +++ b/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx @@ -262,7 +262,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(caster->GetOutput(), argv[2]) + itk::WriteImage(caster->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/RelabelComponentImageFilter.cxx b/Examples/Segmentation/RelabelComponentImageFilter.cxx index c64b40877ff..e4225484bbc 100644 --- a/Examples/Segmentation/RelabelComponentImageFilter.cxx +++ b/Examples/Segmentation/RelabelComponentImageFilter.cxx @@ -107,19 +107,19 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet relabeler->SetInput(input); - itk::WriteImage(relabeler->GetOutput(), argv[2]) - // Software Guide : EndCodeSnippet + itk::WriteImage(relabeler->GetOutput(), argv[2]); + // Software Guide : EndCodeSnippet - // Software Guide : BeginLatex - // - // We can now query the size of each one of the connected components, both - // in pixel units and in physical units. - // - // Software Guide : EndLatex + // Software Guide : BeginLatex + // + // We can now query the size of each one of the connected components, both + // in pixel units and in physical units. + // + // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - using SizesInPixelsType = std::vector; + // Software Guide : BeginCodeSnippet + using SizesInPixelsType = std::vector; const SizesInPixelsType & sizesInPixels = relabeler->GetSizeOfObjectsInPixels(); diff --git a/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx b/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx index ae5740a8160..a0710fc87be 100644 --- a/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx +++ b/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx @@ -566,18 +566,19 @@ main(int argc, char * argv[]) caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); itk::WriteImage(caster1->GetOutput(), - outputImageFilePrefix + "Smoothing.png") + outputImageFilePrefix + "Smoothing.png"); - caster2->SetInput(gradientMagnitude->GetOutput()); + caster2->SetInput(gradientMagnitude->GetOutput()); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); itk::WriteImage(caster2->GetOutput(), - outputImageFilePrefix + "GradientMagnitude.png") + outputImageFilePrefix + "GradientMagnitude.png"); - caster3->SetInput(sigmoid->GetOutput()); + caster3->SetInput(sigmoid->GetOutput()); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - itk::WriteImage(caster3->GetOutput(),outputImageFilePrefix + "Sigmoid.png")) + itk::WriteImage(caster3->GetOutput(), + outputImageFilePrefix + "Sigmoid.png"); caster4->SetInput(fastMarching->GetOutput()); caster4->SetOutputMinimum(0); @@ -689,16 +690,16 @@ main(int argc, char * argv[]) std::cout << "RMS change: " << shapeDetection->GetRMSChange() << std::endl; itk::WriteImage(caster4->GetOutput(), - outputImageFilePrefix + "FastMarching.png") + outputImageFilePrefix + "FastMarching.png"); - // The following writer type is used to save the output of the - // time-crossing map in a file with appropriate pixel representation. The - // advantage of saving this image in native format is that it can be used - // with a viewer to help determine an appropriate threshold to be used on - // the output of the fastmarching filter. - // - using InternalWriterType = itk::ImageFileWriter; + // The following writer type is used to save the output of the + // time-crossing map in a file with appropriate pixel representation. The + // advantage of saving this image in native format is that it can be used + // with a viewer to help determine an appropriate threshold to be used on + // the output of the fastmarching filter. + // + using InternalWriterType = itk::ImageFileWriter; auto mapWriter = InternalWriterType::New(); mapWriter->SetInput(fastMarching->GetOutput()); diff --git a/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx b/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx index e5f78cfd2cd..28228af19d5 100644 --- a/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx @@ -146,6 +146,7 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); + const auto input = itk::ReadImage(argv[1]); // We now declare the type of the \doxygen{FastMarchingImageFilter} that // will be used to generate the initial level set in the form of a distance @@ -245,7 +246,6 @@ main(int argc, char * argv[]) thresholdSegmentation->SetInput(fastMarching->GetOutput()); thresholdSegmentation->SetFeatureImage(input); thresholder->SetInput(thresholdSegmentation->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet // @@ -331,13 +331,12 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - const InternalImageType * inputImage = - itk::ReadImage(argv[1]); + const auto inputImage = itk::ReadImage(argv[1]); fastMarching->SetOutputRegion(inputImage->GetBufferedRegion()); fastMarching->SetOutputSpacing(inputImage->GetSpacing()); fastMarching->SetOutputOrigin(inputImage->GetOrigin()); fastMarching->SetOutputDirection(inputImage->GetDirection()); - itk::WriteImage(thresholder->GetOutput(), argv[2]) + itk::WriteImage(thresholder->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { @@ -363,17 +362,10 @@ main(int argc, char * argv[]) // We write out some intermediate images for debugging. These images can // help tune parameters. // - using InternalWriterType = itk::ImageFileWriter; - auto mapWriter = InternalWriterType::New(); - mapWriter->SetInput(fastMarching->GetOutput()); - mapWriter->SetFileName("fastMarchingImage.mha"); - mapWriter->Update(); - - auto speedWriter = InternalWriterType::New(); - speedWriter->SetInput(thresholdSegmentation->GetSpeedImage()); - speedWriter->SetFileName("speedTermImage.mha"); - speedWriter->Update(); + itk::WriteImage(fastMarching->GetOutput(), "fastMarchingImage.mha"); + itk::WriteImage(thresholdSegmentation->GetSpeedImage(), + "speedTermImage.mha"); // Software Guide : BeginLatex // diff --git a/Examples/Segmentation/VectorConfidenceConnected.cxx b/Examples/Segmentation/VectorConfidenceConnected.cxx index 6de9acd4fcf..e105ef38bf8 100644 --- a/Examples/Segmentation/VectorConfidenceConnected.cxx +++ b/Examples/Segmentation/VectorConfidenceConnected.cxx @@ -126,7 +126,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - confidenceConnected->SetInput(reader->GetOutput()); + confidenceConnected->SetInput(input); // Software Guide : EndCodeSnippet @@ -243,7 +243,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - itk::WriteImage(confidenceConnected->GetOutput(), argv[2]) + itk::WriteImage(confidenceConnected->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/WatershedSegmentation1.cxx b/Examples/Segmentation/WatershedSegmentation1.cxx index 8c3166f09f1..542ede91c86 100644 --- a/Examples/Segmentation/WatershedSegmentation1.cxx +++ b/Examples/Segmentation/WatershedSegmentation1.cxx @@ -212,7 +212,7 @@ main(int argc, char * argv[]) try { - itk::WriteImage(colormapper->GetOutput(), argv[2]) + itk::WriteImage(colormapper->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & e) { diff --git a/Examples/Segmentation/WatershedSegmentation2.cxx b/Examples/Segmentation/WatershedSegmentation2.cxx index 2821e223c1f..c1583a27863 100644 --- a/Examples/Segmentation/WatershedSegmentation2.cxx +++ b/Examples/Segmentation/WatershedSegmentation2.cxx @@ -106,7 +106,7 @@ main(int argc, char * argv[]) try { - itk::WriteImage(colorMapFilter->GetOutput(), argv[2]) + itk::WriteImage(colorMapFilter->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx b/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx index 10b16884c18..51bb179ff90 100644 --- a/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx +++ b/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx @@ -51,7 +51,7 @@ main(int argc, char * argv[]) using ImageMaskSpatialObject = itk::ImageMaskSpatialObject<3>; using ImageType = ImageMaskSpatialObject::ImageType; - using ImageType::Pointer input; + ImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/BayesianClassifier.cxx b/Examples/Statistics/BayesianClassifier.cxx index 4142be8674c..56d70ea9e46 100644 --- a/Examples/Statistics/BayesianClassifier.cxx +++ b/Examples/Statistics/BayesianClassifier.cxx @@ -132,7 +132,7 @@ main(int argc, char * argv[]) // try { - itk::WriteImage(rescaler->GetOutput(), labelMapImageFileName) + itk::WriteImage(rescaler->GetOutput(), labelMapImageFileName); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/BayesianClassifierInitializer.cxx b/Examples/Statistics/BayesianClassifierInitializer.cxx index 0d7ae1d276f..9d3ed7e1a9e 100644 --- a/Examples/Statistics/BayesianClassifierInitializer.cxx +++ b/Examples/Statistics/BayesianClassifierInitializer.cxx @@ -85,7 +85,7 @@ main(int argc, char * argv[]) itk::BayesianClassifierInitializationImageFilter; auto bayesianInitializer = BayesianInitializerType::New(); - using ImageType::Pointer input; + ImageType::Pointer input; try { input = itk::ReadImage(argv[1]); @@ -115,7 +115,7 @@ main(int argc, char * argv[]) try { - itk::WriteImage(bayesianInitializer->GetOutput(), argv[2]) + itk::WriteImage(bayesianInitializer->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageEntropy1.cxx b/Examples/Statistics/ImageEntropy1.cxx index 0c43e4965c6..b115d608499 100644 --- a/Examples/Statistics/ImageEntropy1.cxx +++ b/Examples/Statistics/ImageEntropy1.cxx @@ -84,7 +84,7 @@ main(int argc, char * argv[]) using ImageType = itk::Image; // Software Guide : EndCodeSnippet - using ImageType::Pointer input; + ImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/ImageHistogram1.cxx b/Examples/Statistics/ImageHistogram1.cxx index 759abb6f4b2..4ac85cf5448 100644 --- a/Examples/Statistics/ImageHistogram1.cxx +++ b/Examples/Statistics/ImageHistogram1.cxx @@ -92,7 +92,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ImageType::Pointer input; + ImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/ImageHistogram2.cxx b/Examples/Statistics/ImageHistogram2.cxx index 1fbadf48cc6..64bc2f5f892 100644 --- a/Examples/Statistics/ImageHistogram2.cxx +++ b/Examples/Statistics/ImageHistogram2.cxx @@ -72,9 +72,9 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using ImageType = itk::Image; - using ImageType::Pointer = input; // Software Guide : EndCodeSnippet + ImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/ImageHistogram3.cxx b/Examples/Statistics/ImageHistogram3.cxx index 28680cdeed8..2e6637a9e3e 100644 --- a/Examples/Statistics/ImageHistogram3.cxx +++ b/Examples/Statistics/ImageHistogram3.cxx @@ -80,7 +80,7 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; // Software Guide : EndCodeSnippet - using RGBImageType::Pointer input; + RGBImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/ImageHistogram4.cxx b/Examples/Statistics/ImageHistogram4.cxx index 5ba993b9065..ed204f6f290 100644 --- a/Examples/Statistics/ImageHistogram4.cxx +++ b/Examples/Statistics/ImageHistogram4.cxx @@ -89,7 +89,7 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; // Software Guide : EndCodeSnippet - using RGBImageType::Pointer input; + RGBImageType::Pointer input; try { input = itk::ReadImage(argv[1]); diff --git a/Examples/Statistics/ScalarImageKmeansClassifier.cxx b/Examples/Statistics/ScalarImageKmeansClassifier.cxx index e40a495959d..d72d0f148d0 100644 --- a/Examples/Statistics/ScalarImageKmeansClassifier.cxx +++ b/Examples/Statistics/ScalarImageKmeansClassifier.cxx @@ -167,7 +167,7 @@ main(int argc, char * argv[]) using OutputImageType = KMeansFilterType::OutputImageType; try { - itk::WriteImage(kmeansFilter->GetOutput(), outputImageFileName) + itk::WriteImage(kmeansFilter->GetOutput(), outputImageFileName); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ScalarImageKmeansModelEstimator.cxx b/Examples/Statistics/ScalarImageKmeansModelEstimator.cxx index 5801ba6f588..46fbbca9030 100644 --- a/Examples/Statistics/ScalarImageKmeansModelEstimator.cxx +++ b/Examples/Statistics/ScalarImageKmeansModelEstimator.cxx @@ -62,6 +62,7 @@ main(int argc, char * argv[]) using ImageType = itk::Image; + ImageType::Pointer input; try { const auto input = itk::ReadImage(argv[1]);