Apply Accumulate Image Filter#
Synopsis#
Accumulate pixels of an image along a selected direction.
Results#
Code#
C++#
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkAccumulateImageFilter.h"
int
main(int argc, char * argv[])
{
if (argc != 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName> <OutputFileName> <Dimension>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
auto accumulateDimension = static_cast<unsigned int>(std::stoi(argv[3]));
constexpr unsigned int Dimension = 3;
using InputPixelType = unsigned char;
using InputImageType = itk::Image<InputPixelType, Dimension>;
const auto input = itk::ReadImage<InputImageType>(inputFileName);
using OutputPixelType = double;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;
using FilterType = itk::AccumulateImageFilter<InputImageType, OutputImageType>;
auto filter = FilterType::New();
filter->SetInput(input);
filter->SetAccumulateDimension(accumulateDimension);
try
{
itk::WriteImage(filter->GetOutput(), outputFileName);
}
catch (const itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TInputImage, typename TOutputImage>
class AccumulateImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage> Implements an accumulation of an image along a selected direction.
This class accumulates an image along a dimension and reduce the size of this dimension to 1. The dimension being accumulated is set by AccumulateDimension.
Each pixel is the cumulative sum of the pixels along the collapsed dimension and reduce the size of the accumulated dimension to 1 (only on the accumulated).
The dimensions of the InputImage and the OutputImage must be the same.
This class is parameterized over the type of the input image and the type of the output image.
This filter was contributed by Emiliano Beronich
- Author
Emiliano Beronich
- See
GetAverageSliceImageFilter
Subclassed by itk::GetAverageSliceImageFilter< TInputImage, TOutputImage >