HELP! Re: [Insight-users] ImportImageFilter & TileImageFilter =
troubles!
Alberto Bert
bert at isi.it
Fri Mar 31 08:05:25 EST 2006
Hi floks!
did you have that chance to take a look to the code?
Is that a bug?
Sorry for bothering, but I really need help...
Thanks,
Alberto
On Mar 28, 2006 at 04:54:18PM +0200, Alberto Bert wrote:
> Ops, I'm sorry, I forgot the attachment ;-)
>
> Alberto
>
> On Mar 28, 2006 at 09:43:41AM -0500, Andinet Enquobahrie wrote:
> > Alberto Bert wrote:
> >
> > >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 wnat 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.
> > >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...
> > >
> > >
> > Hi Alberto,
> >
> > Can you post a portion of your code so that we can better help you debug
> > the problem? For example,
> >
> > 1) Declaration of your input and output image types
> >
> > 2) Declaration of the TileImageFilter type and
> >
> > 3) Code fragment where you actually tile the three input images
> >
> > etc...
> >
> > -Andinet
> >
> >
> >
> > >What am I doing wrong? Please help, it's one week I'm fighting with this
> > >bug!
> > >
> > >Linux
> > >itk 2.6.0 tarball
> > >gcc-4.0
> > >
> > >Thanks,
> > >Alberto
> > >_______________________________________________
> > >Insight-users mailing list
> > >Insight-users at itk.org
> > >http://www.itk.org/mailman/listinfo/insight-users
> > >
> > >
> > >
> > >
> >
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> /*=========================================================================
>
> Program: Insight Segmentation & Registration Toolkit
> Module: $RCSfile: Image5.cxx,v $
> Language: C++
> Date: $Date: 2005/02/08 03:51:53 $
> Version: $Revision: 1.15 $
>
> Copyright (c) Insight Software Consortium. All rights reserved.
> See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
>
> This software is distributed WITHOUT ANY WARRANTY; without even
> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE. See the above copyright notices for more information.
>
> =========================================================================*/
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
>
>
>
> #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;
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list