[Insight-users] Re: ImageSeriesReadWrite

Luis Ibanez luis.ibanez at kitware.com
Sat Mar 26 11:34:21 EST 2005


Hi Amos,

The problem that you are facing is that MetaImage is not intended
to read *any* fileformat. Only those of files in RAW format.

Listing your .TIFF images inside the metaimage reader will only
work if those files are uncompressed and their binary information
is at the very end of the files.



The class that you want to use is the

                     ArchetypeSeriesFileNames
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ArchetypeSeriesFileNames.html

along with the ImageSeriesReader.


Note that what you really have is a set of 2D images that
you want to read into a 4D image.

Therefore you should use code like the following:

itk::ArchetypeSeriesFileNames::Pointer fileIter =
                      itk::ArchetypeSeriesFileNames::New();

std::string regularExpression;
filteIter->SetArchetpe( regularExpression );

itk::ImageSeriesReader<Image4DType>::Pointer reader =
                 itk::ImageSeriesReader<Image4DType>::New();

   reader->SetFileNames( fileIter->GetFileNames() );

   reader->Update();




In the regular expression you should construct the expression that
gathers all your 2D TIFF files.




    Regards,


        Luis




------------------
Amos wrote:

> Hello Luis, 
> 
> 
>      I am a univerisity student currently handling a project about 4D data
> analysis. I need to import a 4D image into my program. I think i need your
> help about NumericSeriesFileNames. I saw your reply on 2004 August advising
> a programmer about using NumericSeriesFileNames in www.itk.org. to get a 3D
> file but setting up the NumericSeriesFileNames with parameters. 
> 
> 
> 
> """"""""""""""""""""""""""""""""""""""""""""""""""""
> 
> The essential code will look like:
> 
> 
> 
> 
> 
>    typedef itk::NumericSeriesFileNames	  NameGeneratorType;
> 
> 
> 
>    NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
> 
> 
> 
>    nameGenerator->SetStartIndex( first );
> 
>    nameGenerator->SetEndIndex( last );
> 
>    nameGenerator->SetIncrementIndex( 1 );
> 
> 
> 
>    nameGenerator->SetSeriesFormat( "myImages%04d.png" );
> 
> 
> 
>    seriesWriter->SetFileNames( nameGenerator->GetFileNames()  );
> 
> """"""""""""""""""""""""""""""""""""""""""""""""""""
> 
> 
> 
> I used your method to input 6 x 3D files and combine it to a 4D file, but it
> doesn't work.
> 
> 
> 
>      My case: I have 6 x 100 Tiff images. My prof suggested me to use .mhd
> header files as a header file for my program to read.
> 
> For each header file, i have these:
> 
> 
> 
> NDims = 3
> 
> DimSize = 100 100 100
> 
> ElementSpacing = 0.44082 0.44082 0.44082 
> 
> Position = 0 0 0 
> 
> ElementByteOrderMSB = False
> 
> ElementType = MET_USHORT
> 
> HeaderSize = -1
> 
> ElementDataFile = LIST
> 
> r_000000.0000.tif
> 
> r_000000.0001.tif
> 
> r_000000.0002.tif
> 
> ...
> 
> r_000000.0099.tif
> 
> 
> 
> Then i put these codes in my Cxx file.
> 
> 
> 
> int main( int argc, char **argv ) {
> 
> 
> 
> 	// Define the type of the Image type.
> 
> 	typedef unsigned short PixelType;
> 
> 
> 
> 	typedef itk::Image< PixelType, 3 > Image3DType;
> 
> 	typedef itk::Image< PixelType, 4 > Image4DType;
> 
> 	typedef itk::CastImageFilter<Image3DType, Image4DType>
> CastFilterType;
> 
> 	itk::NumericSeriesFileNames::Pointer fileIter =
> itk::NumericSeriesFileNames::New();
> 
> 
> 
> 	fileIter->SetStartIndex(0);
> 
> 	fileIter->SetEndIndex(1);
> 
> 	fileIter->SetIncrementIndex(1);
> 
> 	fileIter->SetSeriesFormat("vol%02d.mhd");
> 
> 
> 
> 	itk::ImageSeriesReader<Image4DType>::Pointer reader =
> itk::ImageSeriesReader<Image4DType>::New();
> 
> 	reader->SetFileNames( fileIter->GetFileNames() );
> 
> 	reader->Update();
> 
> 
> 
> It compiles, but the result is that: 
> 
> 
> 
> MetaImage: M_ReadElements: data not read completely 
> 
>    ideal = 10000 : actual = 296
> 
> MetaImage: M_ReadElements: data not read completely 
> 
>    ideal = 10000 : actual = 0
> 
> ...
> 
> (repeat so many times with the same error message)
> 
> 
> 
> It seems to me that what the NumericSeriesFileNames did is just 
> 
> read the .mhd file expecting 10000 byte size since it is 100x100 defined in
> the header, but the actually "Compressed" tiff file is much less. So i
> wonder is there anything i could import series of Tiff files as 3D and
> combine them into a 4D file?
> 
> 
> 
> note: my goal is to get a 4D files from 6x100 2d Tiff Images.
> 
> 
> 
> I look forward for you help as soon as possible. Thanks :D
> 
> 
> 
> Amos Cheung
> 
> Student of SFU
> 
> 
> 
> 





More information about the Insight-users mailing list