[Insight-users] Overwriting TIFF files

Sébastien Fricker sebastien.fricker at phaseview.net
Thu Dec 13 12:11:28 EST 2007


Dear ITK users,

I wrote a program that opens an image, transforms it via the Resample image
filter and writes the result to the original image file (see code fragment
below).

This works fine when I use BMP images.

It does not work when I use TIF images: the original image is not modified.
What happens is that the writer at the end does not do anything: apparently
it cannot open the image for writing, probably because the same image was
open for reading at the beginning of the pipeline.

 

Is this a bug or am I doing something wrong?

How can I modify a TIF file in-place?

 

Thanks for any hint.

 

Sebastien

 

CODE FRAGMENT:

 

--------------------------------------------------------

 

//DEFINE IMAGE TYPES    

const unsigned int Dimension = 2;

typedef unsigned short PixelType;

typedef double InternalPixelType;

typedef itk::Image< PixelType, Dimension > ImageType;

typedef itk::Image< InternalPixelType, Dimension > InternalImageType;

            

//READ INPUT IMAGE

typedef itk::ImageFileReader< ImageType  > ImageReaderType;

ImageReaderType::Pointer  inputImageReader  = ImageReaderType::New();

      

inputImageReader->SetFileName( fileName );

inputImageReader->Update();

ImageType::Pointer inputImage = inputImageReader->GetOutput();

 

 

//RESAMPLE IMAGE

//Define filter, create one instance

typedef itk::ResampleImageFilter< InternalImageType, InternalImageType >
ResampleFilterType;

ResampleFilterType::Pointer resampler = ResampleFilterType::New();

 

resampler->SetInput( inputImage );

      

//MORE CODE HERE TO SET RESAMPLER PARAMETERS 


      

 

//CAST IMAGE TO OUTPUT TYPE

typedef itk::CastImageFilter< 

                             InternalImageType,

                             ImageType > CastFilterType;

CastFilterType::Pointer  caster =  CastFilterType::New();

 

caster->SetInput( resampler->GetOutput() );

 

//WRITE OUTPUT FILE  

typedef itk::ImageFileWriter< ImageType >  WriterType;

WriterType::Pointer      writer =  WriterType::New();

      

writer->SetFileName( fileName );

writer->SetInput( caster->GetOutput() );

writer->Update();

 

--------------------------------------------------------

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071213/110478d1/attachment.html


More information about the Insight-users mailing list