diff --git a/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx b/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx index 991f26ea347..aee6db09332 100644 --- a/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx @@ -134,16 +134,8 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader1 = ReaderType::New(); - auto reader2 = ReaderType::New(); - auto writer = WriterType::New(); - - reader1->SetFileName(argv[1]); - reader2->SetFileName(argv[2]); - writer->SetFileName(argv[3]); + const auto input1 = itk::ReadImage(argv[1]); + const auto input2 = itk::ReadImage(argv[2]); // Software Guide : BeginLatex // @@ -249,18 +241,16 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - diffusion->SetInput(reader1->GetOutput()); - cannySegmentation->SetInput(reader2->GetOutput()); + diffusion->SetInput(input1); + cannySegmentation->SetInput(input2); cannySegmentation->SetFeatureImage(diffusion->GetOutput()); thresholder->SetInput(cannySegmentation->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex // - // Invoking the \code{Update()} method on the writer triggers the - // execution of the pipeline. As usual, the call is placed in a + // As usual, the write image call is placed in a // \code{try/catch} block to handle any exceptions that may be thrown. // // Software Guide : EndLatex @@ -268,7 +258,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[3]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/ConfidenceConnected.cxx b/Examples/Segmentation/ConfidenceConnected.cxx index db69c98e5d9..4b2ac8049e0 100644 --- a/Examples/Segmentation/ConfidenceConnected.cxx +++ b/Examples/Segmentation/ConfidenceConnected.cxx @@ -134,18 +134,8 @@ main(int argc, char * argv[]) itk::CastImageFilter; auto caster = CastingFilterType::New(); - - // We instantiate reader and writer types - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + // Read the input image + const auto input = itk::ReadImage(argv[1]); // Software Guide : BeginLatex // @@ -199,7 +189,7 @@ main(int argc, char * argv[]) // Software Guide : BeginLatex // // Now it is time to create a simple, linear pipeline. A file reader is - // added at the beginning of the pipeline and a cast filter and writer are + // added at the beginning of the pipeline and a cast filter is // added at the end. The cast filter is required here to convert // \code{float} pixel types to integer types since only a few image file // formats support \code{float} types. @@ -207,10 +197,9 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); confidenceConnected->SetInput(smoothing->GetOutput()); caster->SetInput(confidenceConnected->GetOutput()); - writer->SetInput(caster->GetOutput()); // Software Guide : EndCodeSnippet @@ -330,8 +319,8 @@ main(int argc, char * argv[]) // Software Guide : BeginLatex // - // The invocation of the \code{Update()} method on the writer triggers the - // execution of the pipeline. It is recommended to place update calls in a + // The invocation of \code{WriteImage} triggers the + // execution of the pipeline. It is recommended to place write calls in a // \code{try/catch} block in case errors occur and exceptions are thrown. // // Software Guide : EndLatex @@ -339,7 +328,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/ConfidenceConnected3D.cxx b/Examples/Segmentation/ConfidenceConnected3D.cxx index a286289ac24..6a91e0e7e0d 100644 --- a/Examples/Segmentation/ConfidenceConnected3D.cxx +++ b/Examples/Segmentation/ConfidenceConnected3D.cxx @@ -60,15 +60,7 @@ main(int argc, char * argv[]) itk::CastImageFilter; auto caster = CastingFilterType::New(); - - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); + const auto input = itk::ReadImage(argv[1]); using CurvatureFlowImageFilterType = itk::CurvatureFlowImageFilter; @@ -78,10 +70,9 @@ main(int argc, char * argv[]) itk::ConfidenceConnectedImageFilter; auto confidenceConnected = ConnectedFilterType::New(); - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); confidenceConnected->SetInput(smoothing->GetOutput()); caster->SetInput(confidenceConnected->GetOutput()); - writer->SetInput(caster->GetOutput()); smoothing->SetNumberOfIterations(2); smoothing->SetTimeStep(0.05); @@ -123,7 +114,7 @@ main(int argc, char * argv[]) try { - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/ConnectedThresholdImageFilter.cxx b/Examples/Segmentation/ConnectedThresholdImageFilter.cxx index bdbac9226d1..972efb7b792 100644 --- a/Examples/Segmentation/ConnectedThresholdImageFilter.cxx +++ b/Examples/Segmentation/ConnectedThresholdImageFilter.cxx @@ -130,15 +130,7 @@ main(int argc, char * argv[]) // We instantiate reader and writer types // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + const auto input = itk::ReadImage(argv[1]); // Software Guide : BeginLatex // @@ -204,7 +196,6 @@ main(int argc, char * argv[]) smoothing->SetInput(reader->GetOutput()); connectedThreshold->SetInput(smoothing->GetOutput()); caster->SetInput(connectedThreshold->GetOutput()); - writer->SetInput(caster->GetOutput()); // Software Guide : EndCodeSnippet @@ -294,7 +285,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/CurvesLevelSetImageFilter.cxx b/Examples/Segmentation/CurvesLevelSetImageFilter.cxx index 9a8d6deeb46..390027ed2c2 100644 --- a/Examples/Segmentation/CurvesLevelSetImageFilter.cxx +++ b/Examples/Segmentation/CurvesLevelSetImageFilter.cxx @@ -140,18 +140,7 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - - // We instantiate reader and writer types in the following lines. - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + const auto input = itk::ReadImage(argv[1]); // The RescaleIntensityImageFilter type is declared below. This filter will // renormalize image before sending them to writers. @@ -278,7 +267,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); gradientMagnitude->SetInput(smoothing->GetOutput()); sigmoid->SetInput(gradientMagnitude->GetOutput()); @@ -286,7 +275,6 @@ main(int argc, char * argv[]) geodesicActiveContour->SetFeatureImage(sigmoid->GetOutput()); thresholder->SetInput(geodesicActiveContour->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -400,37 +388,25 @@ main(int argc, char * argv[]) auto caster3 = CastFilterType::New(); auto caster4 = CastFilterType::New(); - auto writer1 = WriterType::New(); - auto writer2 = WriterType::New(); - auto writer3 = WriterType::New(); - auto writer4 = WriterType::New(); - caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName("CurvesImageFilterOutput1.png"); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), "CurvesImageFilterOutput1.png"); caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName("CurvesImageFilterOutput2.png"); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), "CurvesImageFilterOutput2.png"); caster3->SetInput(sigmoid->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName("CurvesImageFilterOutput3.png"); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(), "CurvesImageFilterOutput3.png"); caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName("CurvesImageFilterOutput4.png"); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); + itk::WriteImage(caster4->GetOutput(), "CurvesImageFilterOutput4.png"); // The FastMarchingImageFilter requires the user to specify the @@ -440,8 +416,7 @@ main(int argc, char * argv[]) // only after the \code{Update()} methods of this filter has been called // directly or indirectly. // - fastMarching->SetOutputSize( - reader->GetOutput()->GetBufferedRegion().GetSize()); + fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize()); // Software Guide : BeginLatex @@ -455,7 +430,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { @@ -477,8 +452,6 @@ main(int argc, char * argv[]) std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange() << std::endl; - writer4->Update(); - // 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 diff --git a/Examples/Segmentation/FastMarchingImageFilter.cxx b/Examples/Segmentation/FastMarchingImageFilter.cxx index 99fa95b9505..788d719c49b 100644 --- a/Examples/Segmentation/FastMarchingImageFilter.cxx +++ b/Examples/Segmentation/FastMarchingImageFilter.cxx @@ -267,23 +267,14 @@ main(int argc, char * argv[]) // Software Guide : BeginLatex // - // We instantiate reader and writer types in the following lines. + // Read the input image // // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; + const auto input = itk::ReadImage(argv[1]); // Software Guide : EndCodeSnippet - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - - // The RescaleIntensityImageFilter type is declared below. This filter will // renormalize image before sending them to writers. // @@ -398,12 +389,11 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); gradientMagnitude->SetInput(smoothing->GetOutput()); sigmoid->SetInput(gradientMagnitude->GetOutput()); fastMarching->SetInput(sigmoid->GetOutput()); thresholder->SetInput(fastMarching->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -583,13 +573,10 @@ main(int argc, char * argv[]) try { auto caster1 = CastFilterType::New(); - auto writer1 = WriterType::New(); caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName(argv[10]); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), argv[10]) } catch (const itk::ExceptionObject & err) { @@ -601,13 +588,10 @@ main(int argc, char * argv[]) try { auto caster2 = CastFilterType::New(); - auto writer2 = WriterType::New(); caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName(argv[11]); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), argv[11]); } catch (const itk::ExceptionObject & err) { @@ -619,13 +603,10 @@ main(int argc, char * argv[]) try { auto caster3 = CastFilterType::New(); - auto writer3 = WriterType::New(); caster3->SetInput(sigmoid->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName(argv[12]); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(), argv[12]); } catch (const itk::ExceptionObject & err) { @@ -646,8 +627,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - fastMarching->SetOutputSize( - reader->GetOutput()->GetBufferedRegion().GetSize()); + fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize()); // Software Guide : EndCodeSnippet @@ -683,7 +663,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(),argv[2])) } catch (const itk::ExceptionObject & excep) { @@ -696,13 +676,10 @@ main(int argc, char * argv[]) try { auto caster4 = CastFilterType::New(); - auto writer4 = WriterType::New(); caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName("FastMarchingFilterOutput4.png"); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); - writer4->Update(); + itk::WriteImage(caster4->GetOutput(), "FastMarchingFilterOutput4.png") } catch (const itk::ExceptionObject & err) { diff --git a/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx b/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx index b42f3cffc7e..ddc0a58d30b 100644 --- a/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx +++ b/Examples/Segmentation/GeodesicActiveContourImageFilter.cxx @@ -163,18 +163,7 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - - // We instantiate reader and writer types in the following lines. - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + const auto input = itk::ReadImage(argv[1]); // The RescaleIntensityImageFilter type is declared below. This filter will // renormalize image before sending them to writers. @@ -301,7 +290,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); gradientMagnitude->SetInput(smoothing->GetOutput()); sigmoid->SetInput(gradientMagnitude->GetOutput()); @@ -309,7 +298,6 @@ main(int argc, char * argv[]) geodesicActiveContour->SetFeatureImage(sigmoid->GetOutput()); thresholder->SetInput(geodesicActiveContour->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -423,38 +411,29 @@ main(int argc, char * argv[]) auto caster3 = CastFilterType::New(); auto caster4 = CastFilterType::New(); - auto writer1 = WriterType::New(); - auto writer2 = WriterType::New(); - auto writer3 = WriterType::New(); - auto writer4 = WriterType::New(); - caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName("GeodesicActiveContourImageFilterOutput1.png"); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), + "GeodesicActiveContourImageFilterOutput1.png"); caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName("GeodesicActiveContourImageFilterOutput2.png"); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), + "GeodesicActiveContourImageFilterOutput2.png"); caster3->SetInput(sigmoid->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName("GeodesicActiveContourImageFilterOutput3.png"); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(), + "GeodesicActiveContourImageFilterOutput3.png"); caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName("GeodesicActiveContourImageFilterOutput4.png"); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); - + itk::WriteImage(caster4->GetOutput(), + "GeodesicActiveContourImageFilterOutput4.png"); // The FastMarchingImageFilter requires the user to specify the // size of the image to be produced as output. This is done using the @@ -463,8 +442,7 @@ main(int argc, char * argv[]) // only after the \code{Update()} methods of this filter has been called // directly or indirectly. // - fastMarching->SetOutputSize( - reader->GetOutput()->GetBufferedRegion().GetSize()); + fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize()); // Software Guide : BeginLatex @@ -478,7 +456,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { @@ -500,8 +478,6 @@ main(int argc, char * argv[]) std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange() << std::endl; - writer4->Update(); - // 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 diff --git a/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx b/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx index 744830f54d2..53d611942f0 100644 --- a/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx +++ b/Examples/Segmentation/GeodesicActiveContourShapePriorLevelSetImageFilter.cxx @@ -244,18 +244,7 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - - // We instantiate reader and writer types in the following lines. - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + const auto input = itk::ReadImage(argv[1]); // The RescaleIntensityImageFilter type is declared below. This filter will // renormalize image before sending them to writers. @@ -418,7 +407,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - center->SetInput(reader->GetOutput()); + center->SetInput(input); smoothing->SetInput(center->GetOutput()); gradientMagnitude->SetInput(smoothing->GetOutput()); reciprocal->SetInput(gradientMagnitude->GetOutput()); @@ -427,7 +416,6 @@ main(int argc, char * argv[]) geodesicActiveContour->SetFeatureImage(reciprocal->GetOutput()); thresholder->SetInput(geodesicActiveContour->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -539,39 +527,25 @@ main(int argc, char * argv[]) auto caster3 = CastFilterType::New(); auto caster4 = CastFilterType::New(); - auto writer1 = WriterType::New(); - auto writer2 = WriterType::New(); - auto writer3 = WriterType::New(); - auto writer4 = WriterType::New(); - caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput1.png"); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), + "GeodesicActiveContourShapePriorImageFilterOutput1.png"); caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput2.png"); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), + "GeodesicActiveContourShapePriorImageFilterOutput2.png"); caster3->SetInput(reciprocal->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput3.png"); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(), + "GeodesicActiveContourShapePriorImageFilterOutput3.png"); caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput4.png"); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); @@ -904,7 +878,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { @@ -928,7 +902,8 @@ main(int argc, char * argv[]) std::cout << "Parameters: " << geodesicActiveContour->GetCurrentParameters() << std::endl; - writer4->Update(); + itk::WriteImage(caster4->GetOutput(), + "GeodesicActiveContourShapePriorImageFilterOutput4.png"); // The following writer type is used to save the output of the time-crossing @@ -969,125 +944,129 @@ main(int argc, char * argv[]) shape->SetParameters(geodesicActiveContour->GetInitialParameters()); thresholder->SetInput(evaluator->GetOutput()); - writer->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput5.png"); - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), + "GeodesicActiveContourShapePriorImageFilterOutput5.png") - shape->SetParameters(geodesicActiveContour->GetCurrentParameters()); + shape->SetParameters(geodesicActiveContour->GetCurrentParameters()); evaluator->Modified(); - writer->SetFileName( - "GeodesicActiveContourShapePriorImageFilterOutput6.png"); - writer->Update(); - - - // 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; + 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; } diff --git a/Examples/Segmentation/GibbsPriorImageFilter1.cxx b/Examples/Segmentation/GibbsPriorImageFilter1.cxx index 75a68cecb42..6692256de1f 100644 --- a/Examples/Segmentation/GibbsPriorImageFilter1.cxx +++ b/Examples/Segmentation/GibbsPriorImageFilter1.cxx @@ -92,20 +92,8 @@ main(int argc, char * argv[]) using ClassImageType = itk::Image; // Software Guide : EndCodeSnippet - - // We instantiate reader and writer types - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto inputimagereader = ReaderType::New(); - auto trainingimagereader = ReaderType::New(); - auto writer = WriterType::New(); - - inputimagereader->SetFileName(argv[1]); - trainingimagereader->SetFileName(argv[2]); - writer->SetFileName(argv[3]); - + const auto input_image = itk::ReadImage(argv[1]); + const auto training_image = itk::ReadImage(argv[2]); // We convert the input into vector images // @@ -133,13 +121,9 @@ main(int argc, char * argv[]) VecIterator vecIt(vecImage, vecImage->GetBufferedRegion()); vecIt.GoToBegin(); - inputimagereader->Update(); - trainingimagereader->Update(); - using ClassIterator = itk::ImageRegionIterator; - ClassIterator inputIt(inputimagereader->GetOutput(), - inputimagereader->GetOutput()->GetBufferedRegion()); + ClassIterator inputIt(input_image, input_image->GetBufferedRegion()); inputIt.GoToBegin(); // Set up the vector to store the image data @@ -181,7 +165,7 @@ main(int argc, char * argv[]) applyEstimateModel->SetNumberOfModels(NUM_CLASSES); applyEstimateModel->SetInputImage(vecImage); - applyEstimateModel->SetTrainingImage(trainingimagereader->GetOutput()); + applyEstimateModel->SetTrainingImage(training_image); // Run the gaussian classifier algorithm @@ -284,7 +268,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet applyGibbsImageFilter->SetInput(vecImage); applyGibbsImageFilter->SetClassifier(myClassifier); - applyGibbsImageFilter->SetTrainingImage(trainingimagereader->GetOutput()); + applyGibbsImageFilter->SetTrainingImage(training_image); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -299,28 +283,27 @@ main(int argc, char * argv[]) std::cout << "applyGibbsImageFilter: " << applyGibbsImageFilter; - writer->SetInput(applyGibbsImageFilter->GetOutput()); - writer->Update(); - - // 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 7a46104bf54..8e241dc6eaa 100644 --- a/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx +++ b/Examples/Segmentation/HoughTransform2DCirclesImageFilter.cxx @@ -88,12 +88,10 @@ main(int argc, char * argv[]) // // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ReaderType = itk::ImageFileReader; - auto reader = ReaderType::New(); - reader->SetFileName(argv[1]); + using ImageType::Pointer localImage; try { - reader->Update(); + localImage = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excep) { @@ -101,7 +99,6 @@ main(int argc, char * argv[]) std::cerr << excep << std::endl; return EXIT_FAILURE; } - const ImageType::Pointer localImage = reader->GetOutput(); // Software Guide : EndCodeSnippet @@ -146,7 +143,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - houghFilter->SetInput(reader->GetOutput()); + houghFilter->SetInput(localImage); houghFilter->SetNumberOfCircles(std::stoi(argv[3])); houghFilter->SetMinimumRadius(std::stod(argv[4])); @@ -265,15 +262,10 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using WriterType = itk::ImageFileWriter; - auto writer = WriterType::New(); - - writer->SetFileName(argv[2]); - writer->SetInput(localOutputImage); try { - writer->Update(); + itk::WriteImage(localOutputImage, argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx b/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx index bb7b854be80..8acfaddd37a 100644 --- a/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx +++ b/Examples/Segmentation/HoughTransform2DLinesImageFilter.cxx @@ -82,13 +82,10 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using ReaderType = itk::ImageFileReader; - auto reader = ReaderType::New(); - - reader->SetFileName(argv[1]); + using ImageType::Pointer localImage; try { - reader->Update(); + localImage = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excep) { @@ -96,7 +93,6 @@ main(int argc, char * argv[]) std::cerr << excep << std::endl; return EXIT_FAILURE; } - const ImageType::Pointer localImage = reader->GetOutput(); // Software Guide : EndCodeSnippet @@ -144,7 +140,7 @@ main(int argc, char * argv[]) constexpr unsigned char threshBelow = 0; constexpr unsigned char threshAbove = 255; threshFilter->ThresholdOutside(threshBelow, threshAbove); - threshFilter->Update(); + threshlocalImageFilter->Update(); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -306,14 +302,10 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using WriterType = itk::ImageFileWriter; - auto writer = WriterType::New(); - writer->SetFileName(argv[2]); - writer->SetInput(localOutputImage); try { - writer->Update(); + itk::WriteImage(localOutputImage, argv[2]); } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/IsolatedConnectedImageFilter.cxx b/Examples/Segmentation/IsolatedConnectedImageFilter.cxx index 39031d765b8..23f44639a7c 100644 --- a/Examples/Segmentation/IsolatedConnectedImageFilter.cxx +++ b/Examples/Segmentation/IsolatedConnectedImageFilter.cxx @@ -92,18 +92,7 @@ main(int argc, char * argv[]) auto caster = CastingFilterType::New(); - - // We instantiate reader and writer types - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - + const auto input = itk::ReadImage(argv[1]); using CurvatureFlowImageFilterType = itk::CurvatureFlowImageFilter; @@ -144,7 +133,6 @@ main(int argc, char * argv[]) smoothing->SetInput(reader->GetOutput()); isolatedConnected->SetInput(smoothing->GetOutput()); caster->SetInput(isolatedConnected->GetOutput()); - writer->SetInput(caster->GetOutput()); // Software Guide : EndCodeSnippet @@ -211,7 +199,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx b/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx index 0836af1a177..0e79920e792 100644 --- a/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/LaplacianSegmentationLevelSetImageFilter.cxx @@ -125,16 +125,8 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader1 = ReaderType::New(); - auto reader2 = ReaderType::New(); - auto writer = WriterType::New(); - - reader1->SetFileName(argv[1]); - reader2->SetFileName(argv[2]); - writer->SetFileName(argv[3]); + const auto input1 = itk::ReadImage(argv[1]); + const auto input2 = itk::ReadImage(argv[2]); // Software Guide : BeginLatex // @@ -223,11 +215,10 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - diffusion->SetInput(reader1->GetOutput()); - laplacianSegmentation->SetInput(reader2->GetOutput()); + diffusion->SetInput(input1); + laplacianSegmentation->SetInput(input2); laplacianSegmentation->SetFeatureImage(diffusion->GetOutput()); thresholder->SetInput(laplacianSegmentation->GetOutput()); - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -241,7 +232,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[3]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx b/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx index f3dfd7b9863..3f6dd4afce2 100644 --- a/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx +++ b/Examples/Segmentation/NeighborhoodConnectedImageFilter.cxx @@ -101,15 +101,8 @@ main(int argc, char * argv[]) // We instantiate reader and writer types // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); + const auto input = itk::ReadImage(argv[1]); // Software Guide : BeginLatex // @@ -171,10 +164,9 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); neighborhoodConnected->SetInput(smoothing->GetOutput()); caster->SetInput(neighborhoodConnected->GetOutput()); - writer->SetInput(caster->GetOutput()); // Software Guide : EndCodeSnippet @@ -270,7 +262,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(caster->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/RelabelComponentImageFilter.cxx b/Examples/Segmentation/RelabelComponentImageFilter.cxx index c3d44d4506c..c64b40877ff 100644 --- a/Examples/Segmentation/RelabelComponentImageFilter.cxx +++ b/Examples/Segmentation/RelabelComponentImageFilter.cxx @@ -71,15 +71,7 @@ main(int argc, char * argv[]) using OutputImageType = itk::Image; // Software Guide : EndCodeSnippet - - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); + const auto input = itk::ReadImage(argv[1]); // Software Guide : BeginLatex // @@ -114,21 +106,20 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet - relabeler->SetInput(reader->GetOutput()); - writer->SetInput(relabeler->GetOutput()); - writer->Update(); - // Software Guide : EndCodeSnippet + relabeler->SetInput(input); + 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 1d184396bc9..ae5740a8160 100644 --- a/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx +++ b/Examples/Segmentation/ShapeDetectionLevelSetFilter.cxx @@ -245,17 +245,7 @@ main(int argc, char * argv[]) // Software Guide : EndCodeSnippet - // We instantiate reader and writer types in the following lines. - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(inputImageFile); - writer->SetFileName(outputImageFile); - + const auto input = itk::ReadImage(inputImageFile); // The RescaleIntensityImageFilter type is declared below. This filter will // renormalize image before sending them to writers. @@ -389,7 +379,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - smoothing->SetInput(reader->GetOutput()); + smoothing->SetInput(input); gradientMagnitude->SetInput(smoothing->GetOutput()); sigmoid->SetInput(gradientMagnitude->GetOutput()); @@ -397,8 +387,6 @@ main(int argc, char * argv[]) shapeDetection->SetFeatureImage(sigmoid->GetOutput()); thresholder->SetInput(shapeDetection->GetOutput()); - - writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -572,37 +560,26 @@ main(int argc, char * argv[]) auto caster3 = CastFilterType::New(); auto caster4 = CastFilterType::New(); - auto writer1 = WriterType::New(); - auto writer2 = WriterType::New(); - auto writer3 = WriterType::New(); - auto writer4 = WriterType::New(); - const std::string outputImageFilePrefix = itksys::SystemTools::GetFilenameWithoutExtension(outputImageFile); caster1->SetInput(smoothing->GetOutput()); - writer1->SetInput(caster1->GetOutput()); - writer1->SetFileName(outputImageFilePrefix + "Smoothing.png"); caster1->SetOutputMinimum(0); caster1->SetOutputMaximum(255); - writer1->Update(); + itk::WriteImage(caster1->GetOutput(), + outputImageFilePrefix + "Smoothing.png") - caster2->SetInput(gradientMagnitude->GetOutput()); - writer2->SetInput(caster2->GetOutput()); - writer2->SetFileName(outputImageFilePrefix + "GradientMagnitude.png"); + caster2->SetInput(gradientMagnitude->GetOutput()); caster2->SetOutputMinimum(0); caster2->SetOutputMaximum(255); - writer2->Update(); + itk::WriteImage(caster2->GetOutput(), + outputImageFilePrefix + "GradientMagnitude.png") - caster3->SetInput(sigmoid->GetOutput()); - writer3->SetInput(caster3->GetOutput()); - writer3->SetFileName(outputImageFilePrefix + "Sigmoid.png"); + caster3->SetInput(sigmoid->GetOutput()); caster3->SetOutputMinimum(0); caster3->SetOutputMaximum(255); - writer3->Update(); + itk::WriteImage(caster3->GetOutput(),outputImageFilePrefix + "Sigmoid.png")) caster4->SetInput(fastMarching->GetOutput()); - writer4->SetInput(caster4->GetOutput()); - writer4->SetFileName(outputImageFilePrefix + "FastMarching.png"); caster4->SetOutputMinimum(0); caster4->SetOutputMaximum(255); @@ -619,8 +596,7 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - fastMarching->SetOutputSize( - reader->GetOutput()->GetBufferedRegion().GetSize()); + fastMarching->SetOutputSize(input->GetBufferedRegion().GetSize()); // Software Guide : EndCodeSnippet @@ -691,7 +667,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), outputImageFile); } catch (const itk::ExceptionObject & excep) { @@ -712,16 +688,17 @@ main(int argc, char * argv[]) << shapeDetection->GetElapsedIterations() << std::endl; std::cout << "RMS change: " << shapeDetection->GetRMSChange() << std::endl; - writer4->Update(); + itk::WriteImage(caster4->GetOutput(), + 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 015f47005d7..e5f78cfd2cd 100644 --- a/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx +++ b/Examples/Segmentation/ThresholdSegmentationLevelSetImageFilter.cxx @@ -146,15 +146,6 @@ main(int argc, char * argv[]) thresholder->SetOutsideValue(0); thresholder->SetInsideValue(255); - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); - // 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 @@ -252,7 +243,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet thresholdSegmentation->SetInput(fastMarching->GetOutput()); - thresholdSegmentation->SetFeatureImage(reader->GetOutput()); + thresholdSegmentation->SetFeatureImage(input); thresholder->SetInput(thresholdSegmentation->GetOutput()); writer->SetInput(thresholder->GetOutput()); // Software Guide : EndCodeSnippet @@ -340,13 +331,13 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - reader->Update(); - const InternalImageType * inputImage = reader->GetOutput(); + const InternalImageType * inputImage = + itk::ReadImage(argv[1]); fastMarching->SetOutputRegion(inputImage->GetBufferedRegion()); fastMarching->SetOutputSpacing(inputImage->GetSpacing()); fastMarching->SetOutputOrigin(inputImage->GetOrigin()); fastMarching->SetOutputDirection(inputImage->GetDirection()); - writer->Update(); + itk::WriteImage(thresholder->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/VectorConfidenceConnected.cxx b/Examples/Segmentation/VectorConfidenceConnected.cxx index ad450cdbec1..6de9acd4fcf 100644 --- a/Examples/Segmentation/VectorConfidenceConnected.cxx +++ b/Examples/Segmentation/VectorConfidenceConnected.cxx @@ -91,16 +91,8 @@ main(int argc, char * argv[]) using OutputImageType = itk::Image; - // We instantiate reader and writer types - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); + const auto input = itk::ReadImage(argv[1]); - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); // Software Guide : BeginLatex // @@ -135,7 +127,6 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet confidenceConnected->SetInput(reader->GetOutput()); - writer->SetInput(confidenceConnected->GetOutput()); // Software Guide : EndCodeSnippet @@ -252,7 +243,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - writer->Update(); + itk::WriteImage(confidenceConnected->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/Segmentation/WatershedSegmentation1.cxx b/Examples/Segmentation/WatershedSegmentation1.cxx index 88f187f45d0..8c3166f09f1 100644 --- a/Examples/Segmentation/WatershedSegmentation1.cxx +++ b/Examples/Segmentation/WatershedSegmentation1.cxx @@ -105,7 +105,6 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - using FileReaderType = itk::ImageFileReader; using CastFilterType = itk::CastImageFilter; using DiffusionFilterType = itk::VectorGradientAnisotropicDiffusionImageFilter; // Software Guide : EndCodeSnippet - using FileWriterType = itk::ImageFileWriter; - - auto reader = FileReaderType::New(); - reader->SetFileName(argv[1]); + const auto input = itk::ReadImage(argv[1]); auto caster = CastFilterType::New(); @@ -199,9 +195,6 @@ main(int argc, char * argv[]) // Software Guide : EndCodeSnippet - auto writer = FileWriterType::New(); - writer->SetFileName(argv[2]); - // Software Guide : BeginLatex // // The filters are connected into a single pipeline, with readers and @@ -210,17 +203,16 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - caster->SetInput(reader->GetOutput()); + caster->SetInput(input); diffusion->SetInput(caster->GetOutput()); gradient->SetInput(diffusion->GetOutput()); watershed->SetInput(gradient->GetOutput()); colormapper->SetInput(watershed->GetOutput()); - writer->SetInput(colormapper->GetOutput()); // Software Guide : EndCodeSnippet try { - writer->Update(); + itk::WriteImage(colormapper->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & e) { diff --git a/Examples/Segmentation/WatershedSegmentation2.cxx b/Examples/Segmentation/WatershedSegmentation2.cxx index 9bc96270382..2821e223c1f 100644 --- a/Examples/Segmentation/WatershedSegmentation2.cxx +++ b/Examples/Segmentation/WatershedSegmentation2.cxx @@ -55,17 +55,7 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; - // - // We instantiate reader and writer types - // - using ReaderType = itk::ImageFileReader; - using WriterType = itk::ImageFileWriter; - - auto reader = ReaderType::New(); - auto writer = WriterType::New(); - - reader->SetFileName(argv[1]); - writer->SetFileName(argv[2]); + const auto input = itk::ReadImage(argv[1]); // @@ -77,7 +67,7 @@ main(int argc, char * argv[]) auto gradienMagnitudeFilter = GradientMagnitudeFilterType::New(); - gradienMagnitudeFilter->SetInput(reader->GetOutput()); + gradienMagnitudeFilter->SetInput(input); gradienMagnitudeFilter->SetSigma(1.0); @@ -114,11 +104,9 @@ main(int argc, char * argv[]) colorMapFilter->SetInput(watershedFilter->GetOutput()); - writer->SetInput(colorMapFilter->GetOutput()); - try { - writer->Update(); + itk::WriteImage(colorMapFilter->GetOutput(), argv[2]) } catch (const itk::ExceptionObject & excep) { diff --git a/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx b/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx index 68936a4f591..10b16884c18 100644 --- a/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx +++ b/Examples/SpatialObjects/BoundingBoxFromImageMaskSpatialObject.cxx @@ -51,15 +51,10 @@ main(int argc, char * argv[]) using ImageMaskSpatialObject = itk::ImageMaskSpatialObject<3>; using ImageType = ImageMaskSpatialObject::ImageType; - using ReaderType = itk::ImageFileReader; - - auto reader = ReaderType::New(); - - reader->SetFileName(argv[1]); - + using ImageType::Pointer input; try { - reader->Update(); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { @@ -69,7 +64,7 @@ main(int argc, char * argv[]) auto maskSO = ImageMaskSpatialObject::New(); - maskSO->SetImage(reader->GetOutput()); + maskSO->SetImage(input); maskSO->Update(); std::cout << "Bounding Box Region: " diff --git a/Examples/Statistics/BayesianClassifierInitializer.cxx b/Examples/Statistics/BayesianClassifierInitializer.cxx index 62149ac59f8..0d7ae1d276f 100644 --- a/Examples/Statistics/BayesianClassifierInitializer.cxx +++ b/Examples/Statistics/BayesianClassifierInitializer.cxx @@ -85,9 +85,10 @@ main(int argc, char * argv[]) itk::BayesianClassifierInitializationImageFilter; auto bayesianInitializer = BayesianInitializerType::New(); + using ImageType::Pointer input; try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageEntropy1.cxx b/Examples/Statistics/ImageEntropy1.cxx index 09f7c375f74..0c43e4965c6 100644 --- a/Examples/Statistics/ImageEntropy1.cxx +++ b/Examples/Statistics/ImageEntropy1.cxx @@ -84,9 +84,10 @@ main(int argc, char * argv[]) using ImageType = itk::Image; // Software Guide : EndCodeSnippet + using ImageType::Pointer input; try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageHistogram1.cxx b/Examples/Statistics/ImageHistogram1.cxx index 5e2e42f2863..759abb6f4b2 100644 --- a/Examples/Statistics/ImageHistogram1.cxx +++ b/Examples/Statistics/ImageHistogram1.cxx @@ -92,9 +92,10 @@ main(int argc, char * argv[]) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet + using ImageType::Pointer input; try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageHistogram2.cxx b/Examples/Statistics/ImageHistogram2.cxx index a56f77ffb15..1fbadf48cc6 100644 --- a/Examples/Statistics/ImageHistogram2.cxx +++ b/Examples/Statistics/ImageHistogram2.cxx @@ -72,11 +72,12 @@ main(int argc, char * argv[]) constexpr unsigned int Dimension = 2; using ImageType = itk::Image; + using ImageType::Pointer = input; // Software Guide : EndCodeSnippet try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageHistogram3.cxx b/Examples/Statistics/ImageHistogram3.cxx index a1db2133145..28680cdeed8 100644 --- a/Examples/Statistics/ImageHistogram3.cxx +++ b/Examples/Statistics/ImageHistogram3.cxx @@ -80,9 +80,10 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; // Software Guide : EndCodeSnippet + using RGBImageType::Pointer input; try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) { diff --git a/Examples/Statistics/ImageHistogram4.cxx b/Examples/Statistics/ImageHistogram4.cxx index a904696893a..5ba993b9065 100644 --- a/Examples/Statistics/ImageHistogram4.cxx +++ b/Examples/Statistics/ImageHistogram4.cxx @@ -89,9 +89,10 @@ main(int argc, char * argv[]) using RGBImageType = itk::Image; // Software Guide : EndCodeSnippet + using RGBImageType::Pointer input; try { - const auto input = itk::ReadImage(argv[1]); + input = itk::ReadImage(argv[1]); } catch (const itk::ExceptionObject & excp) {