[Insight-users] setSpacing() Ignored writing to files
bollen at ipk-gatersleben.de
bollen at ipk-gatersleben.de
Thu Jan 24 12:28:06 EST 2008
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>:
> 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> 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>
>> 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
>> > http://www.itk.org/mailman/listinfo/insight-users
>> >
>>
>>
>
More information about the Insight-users
mailing list