[Insight-users] Suspect of bug: ImportImageFilter & TileImageFilter
Alberto Bert
bert at isi.it
Tue Apr 11 11:15:42 EDT 2006
Hi all,
I'm experiencing troubles by using the ImportImageFilter together with
the TileImageFilter.
Here I send an example of code where three images are generated in a
loop (in my actual code I want to read them from a tricky format) and
"converted" to itk images by means of the ImportImageFilter. Then I want
to tile them in a 4D Image by using the TileImageFilter, but what I get
is a 4D image with the right dimensions but with the default value (0)
everywhere in the image.
I mean, apparently I throw away all my images at the end of the loop.
I added also a writer inside the loop in order to check if the images
are ok, and each of them is actually ok, just the tiled is wrong...
Is that a bug, or I'm doing something wrong?
Sorry if I post again this problem, but I still didn't solve it and
nobody gave any kind of help so far.
I'm afraid the old thread falled in a kind of "black hole", so I hope that
reposting I have some chances that few more people will read it...
Thank you,
sorry again,
Alberto
> #include "itkImage.h"
> #include "itkImportImageFilter.h"
> // Software Guide : EndCodeSnippet
>
> #include "itkImageFileWriter.h"
> #include "itkTileImageFilter.h"
>
> int main(int argc, char * argv[])
> {
> if( argc < 5 )
> {
> std::cerr << "Usage: " << std::endl;
> std::cerr << argv[0] << " outputImageFile1 outputImageFile2 outputImageFile3 tiledImageFile" << std::endl;
> return 1;
> }
>
> typedef unsigned char PixelType;
> const unsigned int Dimension = 3;
> const unsigned int SeriesDimension = Dimension + 1;
>
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::Image< PixelType, SeriesDimension > ImageSeriesType;
>
> typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;
> typedef itk::TileImageFilter< ImageType, ImageSeriesType > TilerType;
>
> itk::FixedArray< unsigned int, SeriesDimension > layout;
> for(size_t i = 0u; i < SeriesDimension; i++)
> layout[i] = 1u;
> layout[ SeriesDimension - 1 ] = 0u;
>
> TilerType::Pointer tiler = TilerType::New();
> tiler->SetLayout( layout );
>
> ImportFilterType::SizeType size;
> size[0] = 200; // size along X
> size[1] = 200; // size along Y
> size[2] = 200; // size along Z
>
> ImportFilterType::IndexType start;
> start.Fill( 0 );
>
> ImportFilterType::RegionType region;
> region.SetIndex( start );
> region.SetSize( size );
>
> double origin[ Dimension ];
> origin[0] = 0.0; // X coordinate
> origin[1] = 0.0; // Y coordinate
> origin[2] = 0.0; // Z coordinate
>
> double spacing[ Dimension ];
> spacing[0] = 1.0; // along X direction
> spacing[1] = 1.0; // along Y direction
> spacing[2] = 1.0; // along Z direction
>
> const unsigned int numberOfPixels = size[0] * size[1] * size[2];
>
> double radius[] = {80.0, 40.0, 20.0};
> double radius2[] = {1.0, 1.0, 1.0};
>
> for (unsigned int i=0; i<3; i++)
> {
>
> ImportFilterType::Pointer importFilter = ImportFilterType::New();
> importFilter->SetRegion( region );
> importFilter->SetOrigin( origin );
> importFilter->SetSpacing( spacing );
>
> PixelType * localBuffer = new PixelType[ numberOfPixels ];
>
> radius2[i] = radius[i] * radius[i];
> PixelType * it = localBuffer;
> for(unsigned int z=0; z < size[2]; z++)
> {
> const double dz = static_cast<double>( z ) - static_cast<double>(size[2])/2.0;
> for(unsigned int y=0; y < size[1]; y++)
> {
> const double dy = static_cast<double>( y ) - static_cast<double>(size[1])/2.0;
> for(unsigned int x=0; x < size[0]; x++)
> {
> const double dx = static_cast<double>( x ) - static_cast<double>(size[0])/2.0;
> const double d2 = dx*dx + dy*dy + dz*dz;
> *it++ = ( d2 < radius2[i] ) ? 255 : 0;
> }
> }
> }
>
> const bool importImageFilterWillOwnTheBuffer = true;
> importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );
>
> typedef itk::ImageFileWriter< ImageType > WriterType;
> WriterType::Pointer writer = WriterType::New();
> writer->SetFileName( argv[i+1] );
> writer->SetInput( importFilter->GetOutput() );
> try { writer->Update(); }
> catch( itk::ExceptionObject & exp ) { std::cerr << exp << std::endl; }
>
> tiler->SetInput( i, importFilter->GetOutput() );
> }
>
> tiler->Update();
>
> typedef itk::ImageFileWriter< ImageSeriesType > WriterSeriesType;
> WriterSeriesType::Pointer writerSeries = WriterSeriesType::New();
>
> writerSeries->SetFileName( argv[4] );
> writerSeries->SetInput( tiler->GetOutput() );
>
> try
> {
> writerSeries->Update();
> }
> catch( itk::ExceptionObject & exp )
> {
> std::cerr << "Exception caught !" << std::endl;
> std::cerr << exp << std::endl;
> }
>
> return 0;
> }
>
More information about the Insight-users
mailing list