[Insight-users] Filtering all channels of a VectorImage
David Doria
daviddoria at gmail.com
Wed Apr 27 09:13:11 EDT 2011
On Wed, Apr 27, 2011 at 8:57 AM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:
> Hello David,
>
> We are implementing this independent per component filtering in SimpleITK
> for VectorImages.
>
> I am curious as to what filters you are finding it useful to run on a per
> component basis, so that we can try to get those implemented in SimpleITK.
>
> Here is a sample of how we are doing it, it sounds like the same way you
> are doing it:
>
> template <class TImageType> Image
> LogImageFilter::ExecuteInternalVectorImage ( const Image& inImage1 )
> {
> // Define the input and output image types
> typedef TImageType
> InputImageType;
> typedef typename InputImageType::InternalPixelType
> ComponentType;
>
> typedef typename itk::Image<ComponentType,
> InputImageType::ImageDimension> ComponentImageType;
>
> typedef InputImageType OutputImageType;
>
> // Get the pointer to the ITK image contained in image1
> typename InputImageType::ConstPointer image1 =
> dynamic_cast <const InputImageType*> ( inImage1.GetImageBase() );
>
> // Check that ITK image pointer was properly retrieved
> if ( image1.IsNull() )
> {
> sitkExceptionMacro( "Unexpected template dispatch error!" );
> }
>
> typedef itk::VectorIndexSelectionCastImageFilter< InputImageType,
> OutputImageType > ComponentExtratorType;
> typename ComponentExtratorType::Pointer extractor =
> ComponentExtratorType::New();
> extractor->SetInput( image1 );
>
> typedef itk::ImageToVectorImageFilter<ComponentImageType>
> ToVectorFilterType;
> typename ToVectorFilterType::Pointer toVector =
> ToVectorFilterType::New();
>
> unsigned int numComps = image1->GetNumberOfComponentsPerPixel();
> for ( unsigned int i = 0; i < numComps; ++i )
> {
> extractor->SetIndex( i );
> extractor->Update();
>
> Image tmp = this->ExecuteInternal<ComponentImageType>( Image(
> extractor->GetOutput() ) );
>
> typename ComponentImageType::ConstPointer tempITKImage =
> dynamic_cast <const ComponentImageType*> ( tmp.GetImageBase() );
>
> toVector->SetNthInput( i, tempITKImage );
> }
>
> toVector->Update();
>
> return Image( toVector->GetOutput() );
> }
>
I've needed it on RescaleImageIntensity, smoothing, logical operations (as
sometimes a "binary/mask" image is really an RGB image with each channel
identical), thresholding, etc.
I would go as far as to say all filters should be able to do this (without
writing the loop in each one). I'm going to take a look at Juliens solution
now.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110427/8d8fa7c3/attachment.htm>
More information about the Insight-users
mailing list