View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006159ITKpublic2007-12-13 13:252007-12-14 10:58
Reportersebastienfricker 
Assigned ToBill Lorensen 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006159: itkTIFFImageIO does not close opened file
DescriptionIt is not possible to overwrite a TIFF file in-place, ie read a file at the beginning of a pipeline and write to the same file at the end.
The reason is that the file reader never closes the file it reads.

In addition, when the writer fails to write, it does so silently.
See the following code in Itktiffimageio.cxx, in the
TIFFImageIO::InternalWrite function:

 TIFF *tif = TIFFOpen(m_FileName.c_str(), "w");
 if ( !tif )
   {
   itkDebugMacro( << "Returning" );
   return;
   }
Additional InformationExample code:

//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();

 
TagsNo tags attached.
Resolution Date
Sprint
Sprint Status
Attached Files

 Relationships

  Notes
(0009868)
Bill Lorensen (developer)
2007-12-13 13:36

I ran itkTIFFImageIOTest with a tiff file specified as the input and output. The program reported a cryptic error:
TIFFOpen: garf.tif: Cannot open.
(0009869)
Bill Lorensen (developer)
2007-12-13 15:09

Placed m_InternalImage->Clean() after reads. This close the file and does some internal cleanup. Also replaced a DebugMacro with an exception if a file cannot be opend for writing.

See:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkTIFFImageIO.cxx?rev=1.56&root=Insight&sortby=date&view=log [^]
(0009890)
Bill Lorensen (developer)
2007-12-14 10:58

Reporter confirmed a positive result of the bug fix.

rom Sébastien Fricker <sebastien.fricker@phaseview.net>
to Bill Lorensen <bill.lorensen@gmail.com>,
cc Xabier Artaechevarria Artieda <xabiarta@unav.es>,
insight-users@itk.org,
date Dec 14, 2007 10:50 AM
subject RE: [Insight-users] Overwriting TIFF files
    
hide details 10:50 AM (7 minutes ago)
    
    
    
Reply
    
    

Bill,

I tested it and it works perfectly now, so you can close the bug issue.

Thanks a lot!

 

Sebastien

 Issue History
Date Modified Username Field Change
2007-12-13 13:25 sebastienfricker New Issue
2007-12-13 13:34 Bill Lorensen Status new => assigned
2007-12-13 13:34 Bill Lorensen Assigned To => Bill Lorensen
2007-12-13 13:36 Bill Lorensen Note Added: 0009868
2007-12-13 13:36 Bill Lorensen Status assigned => acknowledged
2007-12-13 15:09 Bill Lorensen Status acknowledged => resolved
2007-12-13 15:09 Bill Lorensen Resolution open => fixed
2007-12-13 15:09 Bill Lorensen Note Added: 0009869
2007-12-14 10:58 Bill Lorensen Status resolved => closed
2007-12-14 10:58 Bill Lorensen Note Added: 0009890


Copyright © 2000 - 2018 MantisBT Team