[Insight-users] Pad image with 0 but keep its type what ever it is
lynx.abraxas at freenet.de
lynx.abraxas at freenet.de
Tue Jan 26 16:23:59 EST 2010
Hello!
Is it possible to write a filter-program that takes any type of input image
(eg. float, ushort, char...) and pads it with zeros which is an allowed value
in any image type (as far as I know)? See below my code that give already
trouble with mhd-images since the reader seems not to check if the input image
type matches the type in the mhd-header. What can I do about that?
I also wonder what is the difference between SetPadBound, SetPadLowerBound and
SetPadUpperBound?
Thanks for any help or hints
Lynx
____________________________________
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
//#include <itkPadImageFilter.h>
#include <itkConstantPadImageFilter.h>
#include "itkFilterWatcher2.h"
int main( int argc, char * argv[] )
{
if( argc != 4 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage";
std::cerr << " outputImage";
std::cerr << " pad";
std::cerr << std::endl;
return EXIT_FAILURE;
}
typedef unsigned short InputPixelType;
typedef unsigned short OutputPixelType;
const unsigned int Dimension = 3;
typedef itk::Image<InputPixelType, Dimension> InputImageType;
typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
typedef itk::ImageFileWriter<OutputImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
typedef itk::ConstantPadImageFilter<InputImageType, OutputImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
//filter->SetConstant(0);
unsigned long pad, padding[Dimension];
pad= atoi(argv[3]);
for (unsigned int i= 0; i < Dimension; i++)
padding[i]= pad;
filter->SetPadLowerBound(padding);
filter->SetPadUpperBound(padding);
filter->SetInput(reader->GetOutput());
FilterWatcher watcher(filter, "filter");
filter->Update();
//std::cout << std::endl;
writer->SetFileName(argv[2]);
writer->SetInput(filter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
More information about the Insight-users
mailing list