[Insight-users] Reading several slices into a volume - MetaImageIO
Luis Ibanez
luis . ibanez at kitware . com
Mon, 10 Nov 2003 22:22:08 -0500
Hi Lucas,
Please try the following experiment.
Attempt to read a single one of your files
as a 2D slice.
For doing this, simply create a new MetaImage
header with something like
ObjectType = Image
NDims = 2
DimSize = 256 256
ElementSpacing = 1 1
Position = 0 0
ElementByteOrderMSB = True
ElementType = MET_USHORT
HeaderSize = -1
ElementDataFile = I.001
Your image type will now be
typedef itk::Image<unsigned short, 2> ImageType;
then, just after calling Update() in the reader,
print out the information about the image by
doing something like:
reader->Update();
reader->GetOutput()->Print( std::cout );
If this works for the first slice, then
try replacing the file name in the metaImage
Header with "I.002", then "I.003".
The idea is to verify that your slices are ok
and can be read independently as 2D data.
Please let us know what you find.
Thanks
Luis
--------------------
Lucas Lorenzo wrote:
> Hi all,
>
> I have 136 slices stored in individual files. Each slice is 256 x 256.
> I want to read them into a volume so I wrote the following meta header
> file (B0.mhd) and code:
>
> / ObjectType = Image
> NDims = 3
> DimSize = 256 256 136
> ElementSpacing = 1 1 1
> Position = 0 0 0
> ElementByteOrderMSB = True
> ElementType = MET_USHORT
> HeaderSize = -1
> ElementDataFile = I.%03d 1 136 1
>
>
> #include <itkImage.h>
> #include <itkImageFileReader.h>
>
> int main()
> {
> // Declare the image type
> typedef itk::Image<unsigned short, 3> ImageType;
>
>
> // Declare a reader
> typedef itk::ImageFileReader< ImageType > VolumeReaderType;
> VolumeReaderType::Pointer reader = VolumeReaderType::New();
>
> // Set the name of the file to read
> reader->SetFileName( "B0.mhd" );
>
> // Set the image into which the results should be stored
> ImageType::Pointer imOut;
> imOut = reader->GetOutput();
>
>
> // See if the file can be read - "try" otherwise program will
> // mysteriously exit on failure in the Object factory
> try
> {
> reader->Update();
> }
> catch(itk::ExceptionObject &e)
> {
> std::cout << "Problems reading file format" << std::endl;
> std::cerr << e << std::endl;
> return -1;
> }
>
> return 1;
> }/
>
> And I have the problem that it reads the first file (I.001) but it
> doesn't read the rest:
>
> /Using string 'I.%03d' with values 1 to 136 stepping 1
> file = _I.001_
> file = _I.002_
> MetaImage: M_ReadElements: data not read completely
> ideal = 131072 : actual = 0
> *
> *
> *
> file = _I.136_
> MetaImage: M_ReadElements: data not read completely
> ideal = 131072 : actual = 0/
>
> Could someone please help me to figure out what's wrong?
> Thanks
>
> Lucas Lorenzo
>
> University of Utah
> Nora Eccles Harrison CardioVascular Research and Training Institute
> Fellows Room
> 95 South 2000 East
> Salt Lake City, UT 84112-5000
>
> e-mail: lucas at cvrti . utah . edu
> telephone: 801-587-9536