[Insight-users] Overwriting TIFF files
Sébastien Fricker
sebastien.fricker at phaseview.net
Thu Dec 13 12:56:01 EST 2007
Thank you Xabi,
I have already tested writing to a different name and it works just fine.
Only when input name == output name do I get a problem: the original file is
not modified.
The part of the code that fails is in Itktiffimageio.cxx, in the
TIFFImageIO::InternalWrite function.
The problem appears at the following piece of code:
TIFF *tif = TIFFOpen(m_FileName.c_str(), "w");
if ( !tif )
{
itkDebugMacro( << "Returning" );
return;
}
In my case !tif == true because the image was already open at the beginning
of the pipeline.
Surprisingly it works with BMP images though. Does this mean TIFF files
cannot be modified in-place?
Sebastien
-----Original Message-----
From: insight-users-bounces+sebastien.fricker=phaseview.net at itk.org
[mailto:insight-users-bounces+sebastien.fricker=phaseview.net at itk.org] On
Behalf Of Xabier Artaechevarria Artieda
Sent: jeudi 13 décembre 2007 18:21
To: insight-users at itk.org
Subject: Re: [Insight-users] Overwriting TIFF files
Hi Sébastien,
I think I have done this, sometimes without even realising :(
Try writing with a different name to see if that is the problem.
Good luck,
Xabi
--
Xabier Artaechevarria
Cancer Imaging Laboratory
Centre for Applied Medical Research
www.cima.es
Sébastien Fricker <sebastien.fricker at phaseview.net> ha escrito:
> 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();
>
>
>
> --------------------------------------------------------
>
>
>
>
>
>
----------------------------------------------------------------
Este mensaje ha sido enviado desde https://webmail.unav.es
_______________________________________________
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