[Insight-users] setSpacing() Ignored writing to files

Felix Bollenbeck bollen at ipk-gatersleben.de
Thu Jan 24 10:49:48 EST 2008


Hi ITK Users!

I'm having troubles writing the spacing to a transformed image.
Although the resampler gets the input-image spacing, the written image 
which is read in the next iteration has the default [1 1] spacing 
causing troubles.

The images are written to tiff files and haven an initial spacing of 
.37... after transformation and writing, i read files with [1 1] 
spacing, although

  resample->SetOutputSpacing(fixedImage->GetSpacing());

and fixed image has [.37 .37]!

I have tried png files too, in case this is a TIF specific issue same-so 
I conclude it is my mistake here, but where?

Thanks for your help,

Felix.






  resample->SetSize(    fixedImage->GetLargestPossibleRegion().GetSize() );
  resample->SetOutputOrigin(fixedImage->GetOrigin());
  resample->SetOutputSpacing(fixedImage->GetSpacing());
  resample->SetDefaultPixelValue(0);
  resample->Update();

//#############
  const SpacingType outSpacing = resample->GetOutputSpacing();
  std::cout <<"SIZE spacing-out  " << outSpacing[0]<< "    " << 
outSpacing[1] << std::endl;
//#############


  typedef  unsigned char  OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  typedef itk::CastImageFilter< FixedImageType,OutputImageType > 
CastFilterType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;


  WriterType::Pointer      writer =  WriterType::New();
  CastFilterType::Pointer  caster =  CastFilterType::New();
  writer->SetFileName(outImageName);
  caster->SetInput(resample->GetOutput());
  writer->SetInput(caster->GetOutput());
  writer->Update();


More information about the Insight-users mailing list