Skip to content

Commit

Permalink
STYLE: Use itk::ReadImage/itk::WriteImage in Examples/Segmentations,S…
Browse files Browse the repository at this point in the history
…patialObj
  • Loading branch information
sadhana-r committed Jan 24, 2025
1 parent 52bde6a commit 1fa5632
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 551 deletions.
22 changes: 6 additions & 16 deletions Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ main(int argc, char * argv[])
thresholder->SetOutsideValue(0);
thresholder->SetInsideValue(255);

using ReaderType = itk::ImageFileReader<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;

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<InternalImageType>(argv[1]);
const auto input2 = itk::ReadImage<InternalImageType>(argv[2]);

// Software Guide : BeginLatex
//
Expand Down Expand Up @@ -249,26 +241,24 @@ 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

// Software Guide : BeginCodeSnippet
try
{
writer->Update();
itk::WriteImage(thresholder->GetOutput(), argv[3])
}
catch (const itk::ExceptionObject & excep)
{
Expand Down
25 changes: 7 additions & 18 deletions Examples/Segmentation/ConfidenceConnected.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,8 @@ main(int argc, char * argv[])
itk::CastImageFilter<InternalImageType, OutputImageType>;
auto caster = CastingFilterType::New();


// We instantiate reader and writer types
//
using ReaderType = itk::ImageFileReader<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;

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<InternalImageType>(argv[1]);

// Software Guide : BeginLatex
//
Expand Down Expand Up @@ -199,18 +189,17 @@ 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.
//
// 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


Expand Down Expand Up @@ -330,16 +319,16 @@ 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

// Software Guide : BeginCodeSnippet
try
{
writer->Update();
itk::WriteImage(caster->GetOutput(), argv[2])
}
catch (const itk::ExceptionObject & excep)
{
Expand Down
15 changes: 3 additions & 12 deletions Examples/Segmentation/ConfidenceConnected3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,7 @@ main(int argc, char * argv[])
itk::CastImageFilter<InternalImageType, OutputImageType>;
auto caster = CastingFilterType::New();


using ReaderType = itk::ImageFileReader<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;

auto reader = ReaderType::New();
auto writer = WriterType::New();

reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);
const auto input = itk::ReadImage<InternalImageType>(argv[1]);

using CurvatureFlowImageFilterType =
itk::CurvatureFlowImageFilter<InternalImageType, InternalImageType>;
Expand All @@ -78,10 +70,9 @@ main(int argc, char * argv[])
itk::ConfidenceConnectedImageFilter<InternalImageType, InternalImageType>;
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);
Expand Down Expand Up @@ -123,7 +114,7 @@ main(int argc, char * argv[])

try
{
writer->Update();
itk::WriteImage(caster->GetOutput(), argv[2]);
}
catch (const itk::ExceptionObject & excep)
{
Expand Down
13 changes: 2 additions & 11 deletions Examples/Segmentation/ConnectedThresholdImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,7 @@ main(int argc, char * argv[])

// We instantiate reader and writer types
//
using ReaderType = itk::ImageFileReader<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;

auto reader = ReaderType::New();
auto writer = WriterType::New();

reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);

const auto input = itk::ReadImage<InternalImageType>(argv[1]);

// Software Guide : BeginLatex
//
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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)
{
Expand Down
43 changes: 8 additions & 35 deletions Examples/Segmentation/CurvesLevelSetImageFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<InternalImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;

auto reader = ReaderType::New();
auto writer = WriterType::New();

reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);

const auto input = itk::ReadImage<InternalImageType>(argv[1]);

// The RescaleIntensityImageFilter type is declared below. This filter will
// renormalize image before sending them to writers.
Expand Down Expand Up @@ -278,15 +267,14 @@ 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());

geodesicActiveContour->SetInput(fastMarching->GetOutput());
geodesicActiveContour->SetFeatureImage(sigmoid->GetOutput());

thresholder->SetInput(geodesicActiveContour->GetOutput());
writer->SetInput(thresholder->GetOutput());
// Software Guide : EndCodeSnippet


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
{
Expand All @@ -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
Expand Down
Loading

0 comments on commit 1fa5632

Please sign in to comment.