[Insight-users] Re: FW: Help with reading raw image in ITK

Luis Ibanez luis.ibanez at kitware.com
Tue May 1 18:38:36 EDT 2007


Hi Mitali,

Thanks for letting us know that you managed to read the image
by using the ImageViewer.

You will find instructions on how to create MetaImage headers
in the Data page of www.itk.org:

           http://www.itk.org/HTML/Data.htm

Look at the section:

    "Writing a MetaImage header for raw data"


You may also use the small helper application:


               MetaImageImporter


That is distributed with InsightApplications in the directory:


           InsightApplications/MetaImageImporter



    Regards,


       Luis


-------------------------
More, Mitali J *HS wrote:
> Luis, 
> 
> I am able to read my image using the Image Viewer and it looks right.
> Thanks for all your help. I wonder why ImageJ could not read it right. 
> 
> With reference to your previous email:-
> "
> 
>>BTW, looking back at your code for reading the binary image,
>>you were indicating that the binary file had a header of
>>512 bytes. This is incorrect. The .img file does not have
>>any header. The header information is in the .hdr file.
>>
>>
>>In general, you should not use the RawImageIO class.
>>It is much better to simply write the MetaImage header
>>for the raw file, and then use the ImageFileReader.
> 
> "
> 
> My original image is in the raw format (.smv format) with 512 header
> bytes. I am using the ITK RawImageIO filter (the code snippet I sent
> you) to read it into ITK and save it. That is how I am obtaining the
> .img file that I sent you for testing. Since the .img file was not
> reading right in Image J, I assumed that there was a problem with the
> ITK RawImageIO filter. But that is not the case. 
> 
> Your suggestion for using the MetaImage header is great. Is there any
> documentation that I can use to create the MetaImage header? 
> 
> Thanx, 
> ~Mitali 
> 
> 
> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
> Sent: Monday, April 23, 2007 10:58 AM
> To: More, Mitali J *HS
> Cc: Insight Users
> Subject: Re: FW: Help with reading raw image in ITK
> 
> 
> Hi Mitali,
> 
> 
> My mistake,
> 
> The correct links is to the ImageViewer binary is:
> 
> http://public.kitware.com/pub/itk/InsightApplicationsBin/
> 
> The files in this directory are the binary executables of
> some of the applications in InsightApplications. You don't
> need the source code of InsightApplications in order to use
> these executables. In fact, the whole point of distributing
> the binaries is that users would be able to use them without
> having to download the source code of InsightApplications
> and without having to build the projects.
> 
> 
> 
> As I described in my email, I was able to see your image
> in the ImageViewer, and it appeared normal.
> 
> 
> Please give it a try to this viewer and let us know
> what you find,
> 
> 
>    Thanks
> 
> 
>      Luis
> 
> 
> 
> --------------------------
> More, Mitali J *HS wrote:
> 
>>Luis,
>>
>>Thank you for your response. I am not able to access the link you sent
>>me to download the Image Viewer application.
>>http://public.kitware.com/ftp/pub/itk/InsightApplicationsBin
>>
>>Is there a problem with the page? 
>>
>>Also, this looks like some Application that has been written in ITK.
> 
> Do
> 
>>I need to download and build InsightApplications to use the Image
>>Viewer? Right now, I do not have it built.  
>>
>>If I understand this correctly, ITK is able to read my images
> 
> correctly.
> 
>>There is a problem with MRICro opening them. So, I should be able to
>>display my images correctly using Image Viewer. Is that correct? 
>>
>>Thanks again for taking the time to help me. 
>>
>>Mitali 
>>
>>-----Original Message-----
>>From: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
>>Sent: Saturday, March 31, 2007 12:12 PM
>>To: More, Mitali J *HS
>>Cc: Insight Users
>>Subject: Re: FW: Help with reading raw image in ITK
>>
>>
>>
>>Hi Mitali,
>>
>>Thanks for sending the image.
>>
>>I can read your test_2.hdr + test_2.img image without problem
>>using the ImageViewer application.
>>
>>Also, using your description of the image, I also wrote the
>>MetaImage header for the raw file, and was able to load it
>>into the ImageViewer application. The MetaImage header is
>>attached to this email, please put it in the same directory
>>where you have the file test_2.img.
>>
>>
>>You can get this application from:
>>
>>http://public.kitware.com/ftp/pub/itk/InsightApplicationsBin
>>
>>/ImageViewer.exe
>>
>>If your system is not too recent, you may need to copy also
>>the DLL files:
>>
>>msvcp71.dll
>>msvcp71d.dll
>>msvcr71.dll
>>msvcr71d.dll
>>
>>Note that you must put the DLLs in the *same* directory where
>>you put the ImageViewer application.
>>
>>
>>I was able to see your image by doing :
>>
>>
>>     ImageViewer  test_2.hdr
>>
>>and
>>
>>     ImageViewer  test_2.img
>>
>>
>>Please give it a try to this applications and let us know
>>how it works in your system.
>>
>>
>>BTW, looking back at your code for reading the binary image,
>>you were indicating that the binary file had a header of
>>512 bytes. This is incorrect. The .img file does not have
>>any header. The header information is in the .hdr file.
>>
>>
>>In general, you should not use the RawImageIO class.
>>It is much better to simply write the MetaImage header
>>for the raw file, and then use the ImageFileReader.
>>
>>
>>
>>
>>     Regards,
>>
>>
>>        Luis
>>
>>
>>
>>--------------------------
>>More, Mitali J *HS wrote:
>>
>>
>>>Luis, 
>>>
>>>The image has been uploaded successfully. This is the original 5518 x
>>>3677 image. I read it using ITK and write as img. I was not able to
>>
>>read
>>
>>
>>>using MRICro (not enough memory). ImageJ could open the file. But it
>>>looked messed up. 
>>>
>>>Thanx for helping me out, 
>>>
>>>Mitali
>>>
>>>
>>>
>>>
>>>>>>*From:* More, Mitali J *HS
>>>>>>*Sent:* Tuesday, March 27, 2007 5:14 PM
>>>>>>*To:* 'insight-users at itk.org'
>>>>>>*Subject:* Help with reading raw image in ITK
>>>>>>
>>>>>>
>>>>>>
>>>>>>Hi All,
>>>>>>
>>>>>>
>>>>>>
>>>>>>I am having trouble reading a raw image using ITK's RawImageIO
>>>
>>>filter.
>>>
>>>
>>>
>>>>>>These are 2D images, unsigned short, 5518 x 3677, 512 header bytes,
>>>>>
>>>>>liitle-endian. I have provided all this information in my code. I am
>>>>>attaching my code snippet here: 
>>>>>
>>>>>
>>>>>
>>>>>
>>
> ------------------------------------------------------------------------
> 
>>
> ------------------------------------------------------------------------
> 
>>>>>----
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>#include <iostream>
>>>>>>
>>>>>>#include "itkImageFileReader.h"
>>>>>>
>>>>>>#include "itkRawImageIO.h"
>>>>>>
>>>>>>#include "itkImageFileWriter.h"
>>>>>>
>>>>>>#include "itkImageIOBase.h"
>>>>>>
>>>>>>#include "itkImage.h"
>>>>>>
>>>>>>
>>>>>>
>>>>>>int main( int argc, char * argv[] )
>>>>>>
>>>>>>
>>>>>>
>>>>>>{              
>>>>>>
>>>>>>typedef unsigned short PixelType;
>>>>>>
>>>>>>typedef itk::Image < PixelType, 2 >    ImageType;
>>>>>>
>>>>>>typedef itk::RawImageIO < PixelType,2 > ImageIOType;
>>>>>>
>>>>>>typedef itk::ImageFileReader< ImageType >  ReaderType;
>>>>>>
>>>>>>typedef itk::ImageFileWriter< ImageType >  WriterType;
>>>>>>
>>>>>>
>>>>>>
>>>>>>ImageIOType::Pointer rawImageIO = ImageIOType::New();
>>>>>>
>>>>>>
>>>>>>
>>>>>>rawImageIO->SetFileName( argv[1] );
>>>>>>
>>>>>>rawImageIO->SetFileTypeToBinary();
>>>>>>
>>>>>>rawImageIO->SetHeaderSize(512); 
>>>>>>
>>>>>>rawImageIO->SetFileDimensionality(2);
>>>>>>
>>>>>>
>>>>>>
>>>>>>rawImageIO->SetOrigin( 0, 0.0 );  // origin in millimeters
>>>>>>
>>>>>>rawImageIO->SetOrigin( 1, 0.0 );
>>>>>>
>>>>>>
>>>>>>
>>>>>>rawImageIO->SetDimensions( 0, 5518 );  // size in pixels
>>>>>>
>>>>>>rawImageIO->SetDimensions( 1, 3677 );
>>>>>>
>>>>>>
>>>>>>
>>>>>>rawImageIO->SetSpacing( 0,  0.05 );  // spacing in millimeters
>>>>>>
>>>>>>rawImageIO->SetSpacing( 1,  0.05 );
>>>>>>
>>>>>>
>>>>>>
>>>>>>rawImageIO->SetByteOrderToLittleEndian();
>>>>>>
>>>>>>rawImageIO->SetPixelType(itk::ImageIOBase::SCALAR);
>>>>>>
>>>>>>rawImageIO->SetNumberOfComponents(1);
>>>>>>
>>>>>>
>>>>>>
>>>>>>ReaderType::Pointer reader = ReaderType::New();
>>>>>>
>>>>>>reader->SetImageIO( rawImageIO );
>>>>>>
>>>>>>reader->SetFileName( argv[1] );
>>>>>>
>>>>>>
>>>>>>
>>>>>>WriterType::Pointer writer = WriterType::New();
>>>>>>
>>>>>>writer->SetFileName(argv[2]);
>>>>>>
>>>>>>writer->SetInput(reader->GetOutput());
>>>>>>
>>>>>>
>>>>>>
>>>>>>return EXIT_SUCCESS;
>>>>>>
>>>>>>}
>>>>>>
>>>>>>
>>>>>
>>>>>
> ------------------------------------------------------------------------
> 
>>
> ------------------------------------------------------------------------
> 
>>>>>------------------------------------------------------------------
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>I am writing these images as .img and opening them using Image J.
>>
>>The
>>
>>
>>>>>image looks jumbled and for some reason is read as 8 bit data. What
>>
>>am
>>
>>
>>>>I
>>>>
>>>>
>>>>
>>>>
>>>>>doing wrong? 
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Thanks 
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
> 


More information about the Insight-users mailing list