Skip to content

Commit

Permalink
COMP: use built-in ReadImage and WriteImage convenience functions
Browse files Browse the repository at this point in the history
WriteImage is part of ITK since:
InsightSoftwareConsortium/ITK@60b0984

ReadImage is part of ITK since:
InsightSoftwareConsortium/ITK@aeea88b
  • Loading branch information
dzenanz authored and hjmjohnson committed Dec 28, 2020
1 parent 9d593d0 commit bb9055a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Expand Up @@ -8,7 +8,7 @@ set(ExampleSpecificComponents
)

if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED COMPONENTS Montage ITKImageIO ITKTransformIO ITKTestKernel ${ExampleSpecificComponents})
find_package(ITK 5.2 REQUIRED COMPONENTS Montage ITKImageIO ITKTransformIO ITKTestKernel ${ExampleSpecificComponents})
else()
# when being built as part of ITK, ITKImageIO and ITKTransformIO
# lists of modules are not yet ready, causing a configure error
Expand Down
31 changes: 4 additions & 27 deletions examples/CompleteMontage.cxx
Expand Up @@ -33,29 +33,6 @@
#include "itkBilateralImageFilter.h"
#include "itkComposeImageFilter.h"

template <typename TImage>
typename TImage::Pointer
ReadImage(const char * filename)
{
using ReaderType = itk::ImageFileReader<TImage>;
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->Update();
return reader->GetOutput();
}

template <typename TImage>
void
WriteImage(const TImage * out, const char * filename, bool compress)
{
using WriterType = itk::ImageFileWriter<TImage>;
typename WriterType::Pointer w = WriterType::New();
w->SetInput(out);
w->SetFileName(filename);
w->SetUseCompression(compress);
w->Update();
}

template <typename TransformType>
void
WriteTransform(const TransformType * transform, std::string filename)
Expand Down Expand Up @@ -397,7 +374,7 @@ completeMontage(const itk::TileConfiguration<Dimension> & stageTiles,
for (size_t t = 0; t < stageTiles.LinearSize(); t++)
{
std::string filename = inputPath + stageTiles.Tiles[t].FileName;
typename OriginalImageType::Pointer image = ReadImage<OriginalImageType>(filename.c_str());
typename OriginalImageType::Pointer image = itk::ReadImage<OriginalImageType>(filename.c_str());
typename TileConfig::PointType origin = stageTiles.Tiles[t].Position;
std::cout << 'R' << std::flush;

Expand All @@ -421,7 +398,7 @@ completeMontage(const itk::TileConfiguration<Dimension> & stageTiles,
avgSpacing = std::pow(avgSpacing, 1.0 / Dimension);

image = denoiseImage<PixelType, Dimension>(image, avgSpacing);
WriteImage(image.GetPointer(), (outputPath + stageTiles.Tiles[t].FileName + "-bil.nrrd").c_str(), true);
itk::WriteImage(image.GetPointer(), (outputPath + stageTiles.Tiles[t].FileName + "-bil.nrrd").c_str(), true);
std::cout << 'D' << std::flush;
}

Expand All @@ -439,7 +416,7 @@ completeMontage(const itk::TileConfiguration<Dimension> & stageTiles,
std::string baseFileName = itksys::SystemTools::GetFilenameWithoutLastExtension(stageTiles.Tiles[t].FileName);
std::string flatFileName = baseFileName + "-flat" + fileNameExt;
actualTiles.Tiles[t].FileName = flatFileName;
WriteImage(image.GetPointer(), (outputPath + flatFileName).c_str(), true);
itk::WriteImage(image.GetPointer(), (outputPath + flatFileName).c_str(), true);
}
oImages[t] = image;

Expand Down Expand Up @@ -495,7 +472,7 @@ completeMontage(const itk::TileConfiguration<Dimension> & stageTiles,
std::cout << std::endl;

std::cout << "Writing the final image...";
WriteImage(resampleF->GetOutput(), outFilename.c_str(), true);
itk::WriteImage(resampleF->GetOutput(), outFilename.c_str(), true);
std::cout << "Done!" << std::endl;
}

Expand Down

0 comments on commit bb9055a

Please sign in to comment.