[Insight-users] 16-bit TIFF reading

Nick Arini nick.arini@amersham.com
Tue May 18 14:35:52 EDT 2004


This is a multipart message in MIME format.
--=_alternative 004AB1DD80256E98_=
Content-Type: text/plain; charset="us-ascii"

Dear ITK users, 

I am having trouble trying to read single channel grayscale 16-bit TIFF 
images using the itk::ImageFileReader. 

The tiffinfo output for my test image looks like this: 

<begin tifinfo> 

TIFF Directory at offset 0x8 
  Subfile Type: (0 = 0x0) 
  Image Width: 1392 Image Length: 1040 
  Resolution: 61728, 61728 pixels/cm 
  Bits/Sample: 16 
  Compression Scheme: None 
  Photometric Interpretation: min-is-black 
  Samples/Pixel: 1 
  Max Sample Value: 4095 
  Planar Configuration: single image plane 

<end tiffinfo> 

I am using ITK in a manner similar to the following code fragment: 

<begin code> 

#include "itkImage.h" 
#include "itkImageFileReader.h" 

int main( int argc, char * argv[] ) 
{ 

  if( argc < 3 ) 
    { 
    std::cerr << "Usage: " << argv[0] << " inputImageFile "; 
    std::cerr << " outputImageFile" << std::endl;   
    return 1; 
    } 
 
  typedef  unsigned short PixelType; 

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

  typedef itk::ImageFileReader< ImageType >  ReaderType; 

  ReaderType::Pointer reader = ReaderType::New(); 

  reader->SetFileName( argv[1] ); 

  ImageType::Pointer image = reader->GetOutput(); 

  reader->Update(); 

  return 0; 
} 

<end code> 

The problem that I seem to have is that although I can read the file with 
the correct dimensions the actual pixel values are not the ones I am 
expecting. 

I have successfully read this image into other packages, including Matlab 
and know what I should be getting. The effect I am seeing is similar to 
binning although the new (wrong?) values after reading are not restricted 
to the 8-bit range(0-255). 

Has anyone else had problems with reading 16-bit TIFF images? Is the ITK 
IO TIFF machinery based on libtiff and does this support 16-bit TIFFs. 

I am using ITK version 1.6.0 and observe exactly the same effect on Linux 
(GCC) and WinXP(MSVC++7.1). 
  
Thanks in advance for any help or advice. 

Best regards, 

Nick Arini

--=_alternative 004AB1DD80256E98_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Dear ITK users,</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
I am having trouble trying to read single channel grayscale 16-bit TIFF images using the itk::ImageFileReader.</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
The tiffinfo output for my test image looks like this:</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
&lt;begin tifinfo&gt;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
TIFF Directory at offset 0x8</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Subfile Type: (0 = 0x0)</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Image Width: 1392 Image Length: 1040</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Resolution: 61728, 61728 pixels/cm</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Bits/Sample: 16</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Compression Scheme: None</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Photometric Interpretation: min-is-black</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Samples/Pixel: 1</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Max Sample Value: 4095</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;Planar Configuration: single image plane</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
&lt;end tiffinfo&gt;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
I am using ITK in a manner similar to the following code fragment:</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
&lt;begin code&gt;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
#include &quot;itkImage.h&quot;</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
#include &quot;itkImageFileReader.h&quot;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
int main( int argc, char * argv[] )</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
{</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;if( argc &lt; 3 )</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;{</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; inputImageFile &quot;;</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;std::cerr &lt;&lt; &quot; outputImageFile&quot; &lt;&lt; std::endl; &nbsp;</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;return 1;</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;}</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 &nbsp;<br>
 &nbsp;typedef &nbsp;unsigned short PixelType;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;typedef itk::Image&lt; PixelType, &nbsp;2 &gt; &nbsp; ImageType;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;typedef itk::ImageFileReader&lt; ImageType &gt; &nbsp;ReaderType;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;ReaderType::Pointer reader = ReaderType::New();</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;reader-&gt;SetFileName( argv[1] );</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;ImageType::Pointer image = reader-&gt;GetOutput();</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;reader-&gt;Update();</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp;return 0;</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
}</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
&lt;end code&gt;</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
The problem that I seem to have is that although I can read the file with the correct dimensions the actual pixel values are not the ones I am expecting. </font><font size=3 face="Times New Roman"><br>
</font><font size=2 face="sans-serif"><br>
I have successfully read this image into other packages, including Matlab and know what I should be getting. The effect I am seeing is similar to binning although the new (wrong?) values after reading are not restricted to the 8-bit range(0-255). </font><font size=3 face="Times New Roman"><br>
</font><font size=2 face="sans-serif"><br>
Has anyone else had problems with reading 16-bit TIFF images? Is the ITK IO TIFF machinery based on libtiff and does this support 16-bit TIFFs.</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
I am using ITK version 1.6.0 and observe exactly the same effect on Linux (GCC) and WinXP(MSVC++7.1).</font><font size=3 face="Times New Roman"> </font><font size=2 face="sans-serif"><br>
 </font><font size=3 face="Times New Roman">&nbsp;</font><font size=2 face="sans-serif"><br>
Thanks in advance for any help or advice.</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
Best regards,</font><font size=3 face="Times New Roman"> <br>
</font><font size=2 face="sans-serif"><br>
Nick Arini</font>
<br>
--=_alternative 004AB1DD80256E98_=--



More information about the Insight-users mailing list