[Insight-users] Batch resampling: error writing files of different size

Jolinda Smith jolinda@darkwing.uoregon.edu
Wed, 30 Apr 2003 12:18:47 -0700


Hello,

I'd like to resample several files in a batch process. I've written a
program that parses a text file containing input filenames, output
filenames, and resampling parameters. I set up the pipeline, call
"SetFileName" on the reader and writer, set resampling parameters, and
update the writer. Then I read in new filenames and parameters, set
them, and update the writer again. However, if the size of the output
image is larger that it was for the previous set of files, the writer
fails (referencing memory at 0x00000 when writing metaimage output, an
ITK exception: "error writing image data" when writing analyze output).
A stripped-down version of the code is below.

Is the buffer for the output image data not getting resized correctly?
Is there something else I can do to make this work?

ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
FilterType::Pointer filter = FilterType::New();

filter->SetInput( reader->GetOutput() );
writer->SetInput( filter->GetOutput() );

while (file.good()) {

  getline(file, input_filename);
  getline(file, output_filename);

  OutputImageType::SizeType size;
  file >> size[0];
  file >> size[1];
  file >> size[2];

  reader->SetFileName(input_filename );
  writer->SetFileName(output_filename);
  filter->SetSize(size);

  try
  {
    writer->Update();
  }
  catch (itk::ExceptionObject& err)
  {
    cout << err << endl;
    return -1;
  }

}