[Insight-users] itk addImageFilter do not support VectorImage?

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Jan 8 08:28:20 EST 2013


Hello tao,

The AddImageFilter work just fine for VectorImages. SimpleITK is compiled with with these Image type, and work with adding a constant.

You don't  include the typedef for the AddImageFilter, or the compilation error you are getting. That would help with trying to help you out.

Here are the methods that are generated in SimpleITK for this class:

//                                                                                                                                 
// ExecuteInternal                                                                                                                 
//                                                                                                                                 
template <class TImageType>
Image AddImageFilter::ExecuteInternal ( const Image& inImage1, const Image& inImage2 )
{
 // Define the input and output image types                                                                                       
 typedef TImageType     InputImageType;

 typedef TImageType     InputImageType2;

 typedef InputImageType OutputImageType;

 // Get the pointer to the ITK image contained in image1                                                                          
 typename InputImageType::ConstPointer image1 = this->CastImageToITK<InputImageType>( inImage1 );
 // Get the a pointer to the ITK image contained in image2                                                                        
 typename InputImageType2::ConstPointer image2 = this->CastImageToITK<InputImageType2>( inImage2 );


 typedef itk::AddImageFilter<InputImageType, InputImageType2,  OutputImageType> FilterType;
 // Set up the ITK filter                                                                                                         
 typename FilterType::Pointer filter = FilterType::New();

filter->SetInput( 0, image1 );
filter->SetInput( 1, image2 );



 // Run the ITK filter and return the output as a SimpleITK image                                                                 
 filter->Update();

 typename FilterType::OutputImageType *itkOutImage = filter->GetOutput();
 return Image( itkOutImage );
}


template <class TImageType>
Image AddImageFilter::ExecuteInternal ( double constant, const Image& inImage2 )
{
 // Define the input and output image types                                                                                       
 typedef TImageType     InputImageType;

 typedef TImageType     InputImageType2;

 typedef InputImageType OutputImageType;

 // Get the pointer to the ITK image contained in image2                                                                          
 typename InputImageType2::ConstPointer image2 = this->CastImageToITK<InputImageType2>( inImage2 );

 typedef itk::AddImageFilter<InputImageType, InputImageType2,  OutputImageType> FilterType;
 // Set up the ITK filter                                                                                                         
 typename FilterType::Pointer filter = FilterType::New();

 typename InputImageType::PixelType c;
 NumericTraits<typename InputImageType2::PixelType>::SetLength( c, image2->GetNumberOfComponentsPerPixel() );
 ToPixelType( constant, c );
 filter->SetConstant1( c );
 filter->SetInput2( image2 );


 // Run the ITK filter and return the output as a SimpleITK image                                                                 
 filter->Update();

 typename FilterType::OutputImageType *itkOutImage = filter->GetOutput();
 return Image( itkOutImage );
}

Hope that help,
Brad

On Jan 8, 2013, at 2:17 AM, tao sun <colddiesun at gmail.com> wrote:

> Hi,
> 
> I have a 4D image with 3 channels and I want to add a constant value to it. So I tried addImageFilter:
> 
>       const unsigned int VectorDimension = 3;
>       const unsigned int ImageDimension = 3;
>       typedef itk::Vector< float, VectorDimension >    PixelType;
>       typedef itk::Image< float, ImageDimension > ImageType;
>       filter->Update<ImageType>();
> 
> Everything works fine. But when I deal with the unknown channels image, I have to use VectorImage:
> 
>       const unsigned int ImageDimension = 3;
>       typedef itk::VectorImage<float, ImageDimension> ImageType;
>       filter->Update<ImageType>();
> 
> 
> It complained errors. So is the addImageFilter not support VectorImage yet? What about other intensity image?
> 
> Regards,
> Sun Tao
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> 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