<div>Sebastien,</div>
<div> </div>
<div>Please update and try one more time. I had forgotten to remove the dummy TIFFClose that was in TIFFImageIO.cxx. I'm not sure why my test worked.</div>
<div> </div>
<div>Bill<br></div>
<div class="gmail_quote">On Dec 14, 2007 4:06 AM, Sébastien Fricker <<a href="mailto:sebastien.fricker@phaseview.net">sebastien.fricker@phaseview.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div lang="FR" vlink="blue" link="blue">
<div>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Bill,</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I updated itkTIFFImageIO.cxx and tested it. Now I get an error message when the tiff file cannot be written, which is good.
</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">The other problem is still present though: I can't modify the file in-place because after calling inputImageReader->Update() the file remains open.
</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">To me it looks like TIFFClose</span></font><font face="Courier New" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt">
</span></font><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">does not do what it's supposed to do (i.e. close the file…).</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">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.
</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">But maybe I'm doing something wrong…</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Could you please check it out?</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Thanks a lot.</span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Sebastien</span></font></p>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<p><font face="Arial" color="navy" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </span></font></p>
<div>
<div style="TEXT-ALIGN: center" align="center"><font face="Times New Roman" size="3"><span lang="EN-US" style="FONT-SIZE: 12pt">
<hr align="center" width="100%" size="2">
</span></font></div>
<p><b><font face="Tahoma" size="2"><span lang="EN-US" style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">From:</span></font></b><font face="Tahoma" size="2"><span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">
Bill Lorensen [mailto:<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>] <br><b><span style="FONT-WEIGHT: bold">Sent:</span></b> jeudi 13 décembre 2007 21:13<br><b><span style="FONT-WEIGHT: bold">
To:</span></b> Sébastien Fricker<br><b><span style="FONT-WEIGHT: bold">Cc:</span></b> Xabier Artaechevarria Artieda; <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>
<div>
<div></div>
<div class="Wj3C7c"><br><b><span style="FONT-WEIGHT: bold">Subject:</span></b> Re: [Insight-users] Overwriting TIFF files</div></div></span></font><span lang="EN-US"></span>
<p></p></p></div>
<div>
<div></div>
<div class="Wj3C7c">
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Sebastien,</span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Thanks for submitting the bug report. It was pretty easy to fix.</span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"><a href="http://public.kitware.com/Bug/view.php?id=6159" target="_blank">http://public.kitware.com/Bug/view.php?id=6159</a></span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Please update itkTIFFImageIO.cxx and see if it fixes your problem. If it does, I'll close the bug.</span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Bill</span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"><br><br> </span></font></p></div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">On Dec 13, 2007 1:17 PM, Bill Lorensen <<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>> wrote:</span></font>
</p>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Sebastien,<br><br>This looks like a bug to me. I can't see itkTIFFImageIO closing the file. Also, the write should not silently fail. <br>Please enter a bug report:
<br><a href="http://public.kitware.com/Bug/my_view_page.php" target="_blank">http://public.kitware.com/Bug/my_view_page.php</a><br><font color="#888888"><span style="COLOR: #888888"><br>Bill</span></font> </span></font></p>
<div>
<div>
<p style="MARGIN-BOTTOM: 12pt"><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">On Dec 13, 2007 12:56 PM, Sébastien Fricker <<a href="mailto:sebastien.fricker@phaseview.net" target="_blank">sebastien.fricker@phaseview.net </a>
> wrote:</span></font></p>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt">Thank you Xabi,<br>I have already tested writing to a different name and it works just fine. <br>Only when input name == output name do I get a problem: the original file is
<br>not modified.<br><br>The part of the code that fails is in Itktiffimageio.cxx, in the<br>TIFFImageIO::InternalWrite function.<br>The problem appears at the following piece of code: <br><br> TIFF *tif = TIFFOpen(m_FileName.c_str(), "w");
<br> if ( !tif )<br> {<br> itkDebugMacro( << "Returning" );<br> return;<br> }<br><br>In my case !tif == true because the image was already open at the beginning <br>of the pipeline.<br><br>Surprisingly it works with BMP images though. Does this mean TIFF files
<br>cannot be modified in-place?<br><br>Sebastien</span></font></p>
<div>
<div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"><br>-----Original Message-----<br>From: insight-users-bounces+sebastien.fricker=<a href="mailto:phaseview.net@itk.org" target="_blank">phaseview.net@itk.org
</a><br>[mailto:<a href="mailto:insight-users-bounces+sebastien.fricker=phaseview.net@itk.org" target="_blank"> insight-users-bounces+sebastien.fricker=phaseview.net@itk.org </a>] On<br>Behalf Of Xabier Artaechevarria Artieda
<br>Sent: jeudi 13 décembre 2007 18:21<br>To: <a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org </a><br>Subject: Re: [Insight-users] Overwriting TIFF files<br><br>Hi Sébastien,<br>I think I have done this, sometimes without even realising :(
<br>Try writing with a different name to see if that is the problem.<br>Good luck, <br>Xabi<br><br>--<br>Xabier Artaechevarria<br>Cancer Imaging Laboratory <br>Centre for Applied Medical Research<br><a href="http://www.cima.es/" target="_blank">
www.cima.es</a><br><br><br><br>Sébastien Fricker <<a href="mailto:sebastien.fricker@phaseview.net" target="_blank"> sebastien.fricker@phaseview.net </a>> ha escrito:<br><br>> Dear ITK users,<br>><br>> I wrote a program that opens an image, transforms it via the Resample
<br>image<br>> filter and writes the result to the original image file (see code fragment <br>> below).<br>><br>> This works fine when I use BMP images.<br>><br>> It does not work when I use TIF images: the original image is not
<br>modified.<br>> What happens is that the writer at the end does not do anything: <br>apparently<br>> it cannot open the image for writing, probably because the same image was<br>> open for reading at the beginning of the pipeline.
<br>><br>><br>><br>> Is this a bug or am I doing something wrong? <br>><br>> How can I modify a TIF file in-place?<br>><br>><br>><br>> Thanks for any hint.<br>><br>><br>><br>> Sebastien
<br>><br>><br>><br>> CODE FRAGMENT:<br>><br>><br>><br>> --------------------------------------------------------<br>><br>><br>><br>> //DEFINE IMAGE TYPES<br>><br>> const unsigned int Dimension = 2;
<br>><br>> typedef unsigned short PixelType;<br>> <br>> typedef double InternalPixelType;<br>><br>> typedef itk::Image< PixelType, Dimension > ImageType;<br>><br>> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
<br>><br>><br>><br>> //READ INPUT IMAGE<br>><br>> typedef itk::ImageFileReader< ImageType > ImageReaderType;<br>><br>> ImageReaderType::Pointer inputImageReader = ImageReaderType::New();<br>
><br>> <br>><br>> inputImageReader->SetFileName( fileName );<br>><br>> inputImageReader->Update();<br>><br>> ImageType::Pointer inputImage = inputImageReader->GetOutput();<br>><br>><br>
><br>> <br>><br>> //RESAMPLE IMAGE<br>><br>> //Define filter, create one instance<br>><br>> typedef itk::ResampleImageFilter< InternalImageType, InternalImageType ><br>> ResampleFilterType;
<br>><br>> ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>><br>><br>><br>> resampler->SetInput( inputImage );<br>><br>><br>><br>> //MORE CODE HERE TO SET RESAMPLER PARAMETERS …
<br>><br>><br>><br>><br>><br>> //CAST IMAGE TO OUTPUT TYPE<br>><br>> typedef itk::CastImageFilter<<br>><br>> InternalImageType,<br>><br>> ImageType > CastFilterType;
<br>><br>> CastFilterType::Pointer caster = CastFilterType::New();<br>><br>><br>><br>> caster->SetInput( resampler->GetOutput() );<br>><br>><br>><br>> //WRITE OUTPUT FILE<br>><br>> typedef itk::ImageFileWriter< ImageType > WriterType;
<br>><br>> WriterType::Pointer writer = WriterType::New();<br>><br>><br>><br>> writer->SetFileName( fileName );<br>><br>> writer->SetInput( caster->GetOutput() );<br>><br>> writer->Update();
<br>><br>><br>><br>> --------------------------------------------------------<br>><br>><br>><br>><br>><br>><br><br><br><br>----------------------------------------------------------------<br>
Este mensaje ha sido enviado desde <a href="https://webmail.unav.es/" target="_blank">https://webmail.unav.es</a><br><br>_______________________________________________<br>Insight-users mailing list<br><a href="mailto:Insight-users@itk.org" target="_blank">
Insight-users@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br><br>_______________________________________________<br>Insight-users mailing list
<br><a href="mailto:Insight-users@itk.org" target="_blank">Insight-users@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a></span>
</font></p></div></div></div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div></div></div>
<p><font face="Times New Roman" size="3"><span style="FONT-SIZE: 12pt"> </span></font></p></div></div></div></div></blockquote></div><br>