[Insight-users] Re: FW: Help with reading raw image in ITK
Luis Ibanez
luis.ibanez at kitware.com
Sat Mar 31 11:11:34 EST 2007
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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>
-------------- next part --------------
NDims = 2
DimSize = 5518 3677
ElementSpacing = 1 1
Position = 0 0
ElementByteOrderMSB = False
ElementType = MET_USHORT
HeaderSize = 0
ElementDataFile = test_2.img
More information about the Insight-users
mailing list