[Insight-users] About the second type parameter of itk::Image

Andreas Schuh andreas.schuh.84 at googlemail.com
Thu Feb 19 06:34:03 EST 2009


Hi 李健,

template parameters must be defined at compile time as templates are no
dynamic runtime concept. So if you get a non-ITK Image from another
library where the dimension can only be extracted at runtime, you have
to handle this within a switch or if block. As you may only deal with
2D, 3D and maybe 4D images, the cases aren't too many. Your whole ITK
pipeline has to be instantiated for each of these cases by the compiler,
even if at runtime only the 2D pipeline gets executed. You could do the
following for instance:

void SwitchProcessNonITKImage( const Image* image )
{
const unsigned int dimension = image->GetDimension();

if( dimension == 2 ) ProcessNonITKImage<2>( image );
else if( dimension == 3 ) ProcessNonITKImage<3>( image );
}

template< unsigned int Dimension >
void ProcessNonITKImage( const Image* image )
{
typedef itk::Image<float, Dimension> ImageType;

ImageType::Pointer itkImage = ImageType::New();

// Copy image data or set the buffer pointer of the pixel container to
the image data hold by image
}

Maybe you must also template the ProcessNonITKImage function over the
pixel type if the non-ITK Image type supports several pixel types that
aren't be fixed at compile time, too.

--
regards
Andreas

李健 schrieb:
> Dear all:
>
> It seems that only constants or constant variables can be passed to
> the second type parameter(the image dimension) of itk::Image when
> itk::Image object is created. Am I right? So if I want to import an
> image from the output of a class which is not a itk class to itk
> classes, and the information of the image dimension is stored in a
> nonconstant variable, how can I pass the dimension imformation when I
> was creating the itk::Image object?
>
> Thanks a lot.
>
> ------------------------------------------------------------------------
> 各位明星之间什么关系?Live 人气榜为您悄然揭示。 现在就看看!
> <http://cnweb.search.live.com/xrank/?Form=MEVHAA%20>
> ------------------------------------------------------------------------
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>   



More information about the Insight-users mailing list