[Insight-users] ITK filter that just lets the data pass through
Luis Ibanez
luis.ibanez at kitware.com
Sat Feb 23 20:24:07 EST 2008
Hi Anja,
You may want to take a look at the ChangeInformationImageFilter.
It passes along the pixel data unmodified, and it is usually
applied for changing the image spacing, origin, or direction.
If you use it without setting any new spacing, origin, or
direction, then it will behave like a NULL filter.
From your description it seems that what you actually need
is a multi-plexer filter. You could build one by removing
code from the ChangeInformationImageFilter, and adding the
use of N input image, plus adding a "SelectInput( int )"
method.
... actually ...
....it was easier to do it, than to explain it...
Please find the code attached.
I haven't compiled the code, but it should at least get
you pretty close to what you need.
With this filter you can connect N inputs, and then by
calling the SetSelectInput() method, you will pass only
that input as the output of the filter.
Note that all the input images *MUST have the same TYPE*.
The usage will be like:
typedef itk::Image< char, 3 > ImageType;
typedef itk::SelectInputImageFilter< ImageType > FilterType;
FilterType::Pointer selector = FilterType::New();
selector->SetInput( 0, inputImage0 );
selector->SetInput( 1, inputImage1 );
selector->SetInput( 2, inputImage2 );
selector->SetInput( 3, inputImage3 );
nextFilter->SetInput( selector->GetOutput() );
selector->SetSelectInput( 2 );
nextFilter->Update();
Note that the attached filter is not checking for the
input to acttually exist.... this may not be very safe :-/
You may want to add a bit of safety verification lines,
at the beginning of the GenerateData() method.
If you find this filter useful, and finish crafting it,
it will be great if you post it as a contribution to the
Insight Journal.
http://www.insight-journal.org/InsightJournalManager/index.php
Other users may find it useful too.
Thanks
Luis
------------------
Anja Ende wrote:
> Hi there,
>
> Is there a filter in ITK that does basically nothing and just lets the
> data pass through.
>
> I need this because I have a class with multiple image data sources and
> I wanted the output of the class to just come from one source (which
> could be that filter). So, I basically will adjust the pipeline based on
> which data source is current...
>
> Hope that made some sense...
>
> Cheers,
>
> Anja
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSelectInputImageFilter.h,v $
Language: C++
Date: $Date: 2005/04/18 18:14:58 $
Version: $Revision: 1.9 $
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.
=========================================================================*/
#ifndef __itkSelectInputImageFilter_h
#define __itkSelectInputImageFilter_h
#include "itkImageToImageFilter.h"
namespace itk
{
/** \class SelectInputImageFilter
* \brief Provides the functionality of a multi-plexer.
*
* Given N input images, this filters pass as output the
* input image selected with the method SelectInput(n).
*
*
*/
template <class TInputImage>
class ITK_EXPORT SelectInputImageFilter:
public ImageToImageFilter<TInputImage,TInputImage>
{
public:
/** Standard class typedefs. */
typedef SelectInputImageFilter Self;
typedef ImageToImageFilter<TInputImage,TInputImage> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Typedef to describe the pointer to the input. */
typedef typename TInputImage::Pointer InputImagePointer;
/** Run-time type information (and related methods). */
itkTypeMacro(SelectInputImageFilter, ImageToImageFilter);
/** Copy the input buffer. */
void GenerateData();
/** Set/Get the selected input */
itkSetMacro( SelectedInput, unsigned int );
itkGetMacro( SelectedInput, unsigned int );
protected:
SelectInputImageFilter();
~SelectInputImageFilter() {};
void PrintSelf(std::ostream& os, Indent indent) const;
private:
SelectInputImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
unsigned int m_SelectedInput;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkSelectInputImageFilter.txx"
#endif
#endif
-------------- next part --------------
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSelectInputImageFilter.txx,v $
Language: C++
Date: $Date: 2007/11/21 14:06:50 $
Version: $Revision: 1.16 $
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.
=========================================================================*/
#ifndef _itkSelectInputImageFilter_txx
#define _itkSelectInputImageFilter_txx
#include "itkSelectInputImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkContinuousIndex.h"
#include "itkObjectFactory.h"
namespace itk
{
/**
*
*/
template <class TInputImage>
SelectInputImageFilter<TInputImage>
::SelectInputImageFilter()
{
this->m_SelectedInput = 0;
}
template <class TInputImage>
void
SelectInputImageFilter<TInputImage>
::GenerateOutputInformation()
{
Superclass::GenerateOutputInformation();
// Get pointers to the input and output
typename Superclass::OutputImagePointer output = this->GetOutput();
typename Superclass::InputImagePointer input =
const_cast< TInputImage * >( this->GetInput( this->m_SelectedInput ) );
if( !output || !input )
{
return;
}
// Copy input's information
output->CopyInformation( input );
}
template <class TInputImage>
void
SelectInputImageFilter<TInputImage>
::GenerateInputRequestedRegion()
{
Superclass::GenerateInputRequestedRegion();
if ( this->GetInput( this->m_SelectedInput ) )
{
typename TInputImage::RegionType region;
region.SetSize(this->GetOutput()->GetRequestedRegion().GetSize());
region.SetIndex(this->GetOutput()->GetRequestedRegion().GetIndex() - m_Shift);
InputImagePointer input =
const_cast< TInputImage * >( this->GetInput( this->m_SelectedInput ) );
input->SetRequestedRegion (region);
}
}
template <class TInputImage>
void
SelectInputImageFilter<TInputImage>
::GenerateData()
{
// Get pointers to the input and output
InputImagePointer output = this->GetOutput();
InputImagePointer input =
const_cast< TInputImage * >( this->GetInput( this->m_SelectedInput ));
// No need to copy the bulk data
output->SetPixelContainer(input->GetPixelContainer());
}
/**
*
*/
template <class TInputImage>
void
SelectInputImageFilter<TInputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
os << indent << "Selected Input: " << this->m_SelectedInput << std::endl;
}
} // end namespace itk
#endif
More information about the Insight-users
mailing list