[Insight-users] Overwriting TIFF files

Sébastien Fricker sebastien.fricker at phaseview.net
Fri Dec 14 04:06:40 EST 2007


Bill,

I updated itkTIFFImageIO.cxx and tested it. Now I get an error message when
the tiff file cannot be written, which is good.

The other problem is still present though: I can’t modify the file in-place
because after calling inputImageReader->Update() the file remains open.

 

To me it looks like TIFFClose does not do what it’s supposed to do (i.e.
close the file
).

After TIFFClose is being called during inputImageReader->Update(), if I try
to open the file with another application such as Microsoft Document
Imaging, it says the file is already in use by another application, meaning
ITK did not unlock it.

But maybe I’m doing something wrong


 

Could you please check it out?

 

Thanks a lot.

 

Sebastien

 

 

  _____  

From: Bill Lorensen [mailto:bill.lorensen at gmail.com] 
Sent: jeudi 13 décembre 2007 21:13
To: Sébastien Fricker
Cc: Xabier Artaechevarria Artieda; insight-users at itk.org
Subject: Re: [Insight-users] Overwriting TIFF files

 

Sebastien,

 

Thanks for submitting the bug report. It was pretty easy to fix.

http://public.kitware.com/Bug/view.php?id=6159

 

Please update itkTIFFImageIO.cxx and see if it fixes your problem. If it
does, I'll close the bug.

 

Bill



 

On Dec 13, 2007 1:17 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:

Sebastien,

This looks like a bug to me. I can't see itkTIFFImageIO closing the file.
Also, the write should not silently fail. 
Please enter a bug report:
http://public.kitware.com/Bug/my_view_page.php

Bill 

 

On Dec 13, 2007 12:56 PM, Sébastien Fricker <sebastien.fricker at phaseview.net
> wrote:

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
<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 <http://www.cima.es/> 



Sébastien Fricker < sebastien.fricker at phaseview.net
<mailto: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
<https://webmail.unav.es/> 

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users

_______________________________________________
Insight-users mailing list 
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071214/45b4fa80/attachment-0001.htm


More information about the Insight-users mailing list