int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile projectionDirection"
<< std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned short;
using SliceIteratorType =
try
{
inputImage = itk::ReadImage<ImageType3D>(argv[1]);
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
auto projectionDirection = static_cast<unsigned int>(std::stoi(argv[3]));
unsigned int direction[2];
for (unsigned int i = 0, j = 0; i < 3; ++i)
{
if (i != projectionDirection)
{
direction[j] = i;
j++;
}
}
inputImage->GetRequestedRegion();
index[direction[0]] = requestedRegion.
GetIndex()[direction[0]];
index[1 - direction[0]] = requestedRegion.
GetIndex()[direction[1]];
size[direction[0]] = requestedRegion.GetSize()[direction[0]];
size[1 - direction[0]] = requestedRegion.GetSize()[direction[1]];
region.SetSize(size);
region.SetIndex(index);
outputImage->SetRegions(region);
outputImage->Allocate();
SliceIteratorType inputIt(inputImage, inputImage->GetRequestedRegion());
LinearIteratorType outputIt(outputImage, outputImage->GetRequestedRegion());
inputIt.SetFirstDirection(direction[1]);
inputIt.SetSecondDirection(direction[0]);
outputIt.SetDirection(1 - direction[0]);
outputIt.GoToBegin();
while (!outputIt.IsAtEnd())
{
while (!outputIt.IsAtEndOfLine())
{
++outputIt;
}
outputIt.NextLine();
}
inputIt.GoToBegin();
outputIt.GoToBegin();
while (!inputIt.IsAtEnd())
{
while (!inputIt.IsAtEndOfSlice())
{
while (!inputIt.IsAtEndOfLine())
{
outputIt.Set(std::max(outputIt.Get(), inputIt.Get()));
++inputIt;
++outputIt;
}
outputIt.NextLine();
inputIt.NextLine();
}
outputIt.GoToBegin();
inputIt.NextSlice();
}
try
{
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
A multi-dimensional image iterator that visits image pixels within a region in a "scan-line" order.
const IndexType & GetIndex() const
Multi-dimensional image iterator which only walks a region.
Templated n-dimensional image class.
Define additional traits for native types such as int or float.
SmartPointer< const Self > ConstPointer
ImageBaseType::RegionType RegionType
ImageBaseType::IndexType IndexType
ImageBaseType::SizeType SizeType
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
const IndexValueType * GetIndex() const