[Insight-users] cannot read a tiff image

Luis Ibanez luis.ibanez at kitware.com
Thu Jan 6 21:52:24 EST 2005


Hi Bear,

Thanks for testing the try/catch blocks.

You must however have changed your code when you ran the test,
since according to your email you are writing the image using
"unsigned char" pixels, which are indeed supported by the
JPEG writer.

Please double check the image type that you are using for
instantiating the ImageFileWriter type.


Regarding the fact that you "see" black images when you save
in BMP and PNG,  that reinforces the suspicion above, that
you are actually using "unsigned short" as pixel type.

It is a common mistake to save images using "unsigned short"
as pixel type but having actual pixels values in the range
from 0-255. The result is that most naive viewers show this
images as 'black' images because they are expecting pixel
values in the range 0-65535 (which is 2^32-1).


Yes, I'm sure that your TIFF image was loaded correctly by ITK.
I used the ImageViewer application in order to view your image.
This application is available in the InsightApplications
checkout. The application normalizes the intensities of images
before displaying them, and therefore it makes possible to look
at your image despite the fact that the intensity values do not
fill the dynamic range of 16 bits (unsigned short).



   Regards,



      Luis





------------
bear wrote:

> hi Luis,
>    As you suggest, I add try/catch code, and show that Abort message is indeed
> raised by JpegIO:
>    
> ExceptionObject caught !
> 
> itk::ExceptionObject (0x80f3b28)
> Location: "Unknown"
> File: /home/src/Insight/Code/IO/itkJPEGImageIO.cxx
> Line: 404
> Description: itk::ERROR: JPEGImageIO(0x80f3cc8): JPEG supports unsigned char/int
> only
> 
> This exception does not appear when saving in bmp or png. However, The result
> is a completely *black* image which is wrong. I see cells in Matlab.
> Are you sure TIFF file is already loaded accurately? 
> 
>                                                                 Regards
>                                                                  bear
> 
>>From: Luis Ibanez <luis.ibanez at kitware.com>
>>Reply-To: 
>>To: bear <xgl99 at mails.tsinghua.edu.cn>
>>Subject: Re: [Insight-users] cannot read a tiff image
>>
>>
>>Hi Bear,
>>
>>
>>Your file
>>
>>   http://166.111.201.234/w1.tiff
>>
>>is a non standard TIFF file.
>>
>>The "identify" tool from ImageMagick reports the following:
>>
>>w1.tiff TIFF 1280x1024+0+0 PseudoClass 65536c 16-bit 2.5m 0.050u 0:01
>>
>>e:\program files\imagemagick-5.5.5-q16\identify.exe:
>>
>>unknown field with tag 33628 (0x835c) encountered. (w1.tiff).
>>
>>
>>
>>Note however that ITK read it fine.
>>
>>You get the warnings,..
>>but the image is read from the file without problem.
>>
>>
>>The Abort message that you are receiving is probably produced
>>by the writer->Update(). This commonly happens if you provide
>>an output filename that doesn't correspond to a fileformat
>>recognized by ITK.
>>
>>What *exact* filename did you used for the output ?
>>
>>
>>For a simple verification, just add try/catch blocks around
>>the Update() calls of both the reader and the writer.
>>
>>Chances are that you will see the reader passing fine, and
>>the writer aborting.
>>
>>For a list of the image fileformats supported in ITK, please
>>look at the FAQ
>>
>>         http://www.itk.org/Wiki/ITK_FAQ
>>
>>
>>
>>
>>Regards,
>>
>>
>>    Luis
>>
>>
>>
>>----------------
>>bear wrote:
>>
>>
>>>hi itk-users,
>>>       I have a tiff image(http://166.111.201.234/w1.tiff) which can be read
> 
> by
> 
>>>Matlab's imread() function, but it cannot be read by itk with errors:
>>>
>>>w1.tiff: Warning, unknown field with tag 317 (0x13d) ignored.
>>>w1.tiff: Warning, unknown field with tag 33628 (0x835c) ignored.
>>>Aborted
>>>What is the problem then? Thanks!
>>>
>>>
>>>The code:
>>>
>>>#include "itkImageFileReader.h"
>>>#include "itkImageFileWriter.h"
>>>#include "itkImage.h"
>>>#include "itkRescaleIntensityImageFilter.h"
>>>int main(int ac, char* av[])
>>>{
>>>	if(ac < 3)
>>>    {  
>>>		std::cerr << "Usage: " << av[0] << " input output\n";
>>>		return 1;
>>>    }
>>>	typedef unsigned short InputPixelType;
>>>	typedef itk::Image< InputPixelType, 2 > InputImageType;
>>>	typedef itk::ImageFileReader< InputImageType > ReaderType;
>>>	ReaderType::Pointer reader = ReaderType::New();
>>>	reader->SetFileName( av[1] );
>>>
>>>	reader->Update();
>>>
>>>	typedef unsigned char WritePixelType;
>>>	typedef itk::Image< WritePixelType, 2 > WriteImageType;
>>>	typedef itk::RescaleIntensityImageFilter<
>>>		InputImageType, WriteImageType > RescaleFilterType;
>>>
>>>	RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
>>>	rescaler->SetOutputMinimum(   0 );
>>>	rescaler->SetOutputMaximum( 255 );
>>>	typedef itk::ImageFileWriter< WriteImageType >  WriterType;
>>>
>>>	WriterType::Pointer writer = WriterType::New();
>>>
>>>	writer->SetFileName( av[2] );
>>>
>>>	rescaler->SetInput( reader->GetOutput() );
>>>	writer->SetInput( rescaler->GetOutput() );
>>>
>>>	writer->Update();
>>>	return 0;
>>>
>>>}
>>>
>>>
>>>_______________________________________________
>>>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
> 
> 






More information about the Insight-users mailing list