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

Felix Bollenbeck bollen at ipk-gatersleben.de
Fri Jan 25 07:22:00 EST 2008


Hi Bill,

i couldnt get along with the ChangeInformationImageFilter as suggested:

I used ChangeInformationImageFilter to set both moving and fixed image 
(only fixed image snipped) to unit-spacing as below

  typedef itk::ChangeInformationImageFilter<FixedImageType>  
SpacingFilterType;
  SpacingFilterType::Pointer fixedSpacingFilter= SpacingFilterType::New();
  fixedSpacingFilter->ChangeSpacingOn();
  fixedSpacingFilter->SetInput(fixedImageReader->GetOutput());
  double unitSpacing[2];
  unitSpacing[0] = 1.0;
  unitSpacing[1] = 1.0;
  fixedSpacingFilter->SetOutputSpacing(unitSpacing);
  fixedSpacingFilter->Update();
  FixedImageType::Pointer fixedImage=fixedSpacingFilter->GetOutput();

However doesnt seem to work
/
SIZE spacing-fixed 1    1                                          # ok
SIZE spacing-moving 1   1                                       //# ok/
/0   5938.29   [5.41628, 800, 600, 13.8069, -2.2433]
1   12.1176   [10.7422, 798.529, 591.101, 22.6854, -8.28141]
ExceptionObject caught !

itk::ExceptionObject (0xbb8720)

...

File: 
/home/felix/Desktop/InsightToolkit-3.4.0/Code/Algorithms/itkMeanSquaresImageToImageMetric.txx
Line: 369
Description: itk::ERROR: MeanSquaresImageToImageMetric(0xba11d0): All 
the points mapped to outside of the moving image/

which means something with the set spacing is completely wrong-but what? 
-Im clueless.

Setting the spacing of the written out-image is ignored, as you said. I 
dont see any workarround.

I also tried to set the pixel-res in the data generation side, to match 
ITK's default [1 1] spacing, obtaining different values than I expected, 
which should be due to the inch/mm confusion-Ill check on that.

But i would rather like to handle this on the  ITK side. Would you 
perhaps also suggest the use of a different file format? Im not working 
with medical images (but plants) so changing image properties is not 
that critical to me.

Thanks in advance & Best regards,

    Felix.

-- 
Felix Bollenbeck     		Email: bollen at ipk-gatersleben.de
Pattern Recognition Group       Phone: +49 (0)39482 5344
Leibniz Institute of Plant 	Fax  : +49 (0)39482 5137
Genetics and Crop Plant Research
Correnstr.3 	                http://www.ipk-gatersleben.de
06466 Gatersleben,Germany


Bill Lorensen wrote:
> Felix,
>
> Use itkChangeInformationImageFilter to change spacing,origin,direction...
>
> Bill
>
> On Jan 24, 2008 12:28 PM, <bollen at ipk-gatersleben.de 
> <mailto:bollen at ipk-gatersleben.de>> wrote:
>
>     Hi Bill,
>
>     Yes, a default value coming from MATLABs libtiff is 76px per
>     inch-may I
>     should try to change it on the data generation side...
>
>     I know TIF (custom) tags themself are quite an issue. I have read
>     through some posts regarding SetSpacing() and that its use is
>     discouraged within ITK for obvious reasons.
>
>     Could you give any suggestions how to circumvade the problem in
>     reading/writing the TIFs with different spacing by setting the spacing
>     manually?
>
>     I tried to change the spacing directly on the caster->GetOutput()
>     without effect as it is const I read. I am not shure how to properly
>     change the spacing.
>
>     Best Regards!
>
>     Felix.
>
>
>
>
>
>     Quoting Bill Lorensen <bill.lorensen at gmail.com
>     <mailto:bill.lorensen at gmail.com>>:
>
>     > Felix,
>     >
>     > I just looked at the code in itkTIFFImageIO.cxx. We do in fact
>     compute a
>     > spacing on read if it exists. We don't write the spacing however.
>     >
>     > Here is the dilemma. TIFF supports units of measurement. Either
>     inches,
>     > centimeters or none. In itk, we don't specify units although for
>     medical
>     > imaging they are usually mm's. At write time, we don't know what
>     units to
>     > specify. We could assume mm's and convert that to cm's I guess.
>     >
>     > Bill
>     > On Jan 24, 2008 11:08 AM, Bill Lorensen <bill.lorensen at gmail.com
>     <mailto:bill.lorensen at gmail.com>> wrote:
>     >
>     >> Felix,
>     >>
>     >> I don't believe that png supports spacing in the header. tiff
>     might, but
>     >> maybe we aren't writing the spacing. Can you file a bug
>     following the
>     >> procedure in:
>     >>
>     >> http://www.itk.org/Wiki/ITK_Procedure_for_Contributing_Bug_Fixes
>     >>
>     >> Thanks,
>     >>
>     >> Bill
>     >>   On Jan 24, 2008 10:49 AM, Felix Bollenbeck
>     <bollen at ipk-gatersleben.de <mailto:bollen at ipk-gatersleben.de>>
>     >> wrote:
>     >>
>     >> > 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();
>     >> > _______________________________________________
>     >> > Insight-users mailing list
>     >> > Insight-users at itk.org <mailto:Insight-users at itk.org>
>     >> > http://www.itk.org/mailman/listinfo/insight-users
>     >> >
>     >>
>     >>
>     >
>
>
>
>     _______________________________________________
>     Insight-users mailing list
>     Insight-users at itk.org <mailto:Insight-users at itk.org>
>     http://www.itk.org/mailman/listinfo/insight-users
>
>

    



More information about the Insight-users mailing list