[Insight-users] Create my own filter

Richard Beare richard.beare at gmail.com
Mon Sep 17 19:44:28 EDT 2007


Hi,

You could achieve the same result using masking, if you want to avoid
writing a new filter.

Use the binary threshold filter to create a mask for the >0 part. Use
the MaskImageFilter and MaskNegatedImageFilter to create the two
images and finally add the results together.


 9/18/07, Dan Mueller <dan.muel at gmail.com> wrote:
> Hi Rashedk,
>
> Thanks for describing the filter you are trying to create.
>
> Seeing it is a pixel-wise filter, it's probably best to use the
> itkAndImageFilter as a template (this filter is a specialization of
> itkBinaryFunctorImageFilter). You will need to rename the functor
> (something like "SelectFirstInputIfNotZero") and change the operator()
> method to implement your selection:
>
> inline TOutput operator()( const TInput1 & A, const TInput2 & B)
>   {
>     if ( A > NumericTraits< TInput1 >::Zero )
>       {
>       return static_cast<TOutput>( A );
>       }
>    else
>       {
>       return static_cast<TOutput>( B );
>       }
>   }
>
> You will then need to rename the filter (including
> constructor/destructor), change the functor in the inheritance
> statement, and maybe think about the concept checking.
>
> I have had need for such a filter but been too lazy to create it
> myself -- perhaps you could submit a short Insight Journal article
> (http://www.insight-journal.org) describing the filter?
>
> HTH
>
> Cheers, Dan
>
> On 18/09/2007, rashedk <rashed.vtk at googlemail.com> wrote:
> >
> > Hi Luis,
> >
> > Thanks for your quick reply. I was looking at itkBinaryFunctionImageFilter
> > since this closely resembles what my filter is aiming to accomplish. I have
> > two inputs Image1 and Image2. The output of the filter is a pixel-wise
> > selection of the intensity from either Image1 or Image2. At a pixel (x,y,z)
> > if Image1(x,y,z) > 0 then output(x,y,z) = image1(x,y,z) ELSE if
> > Image1(x,y,z) == 0 then output(x,y,z) = Image2(x,y,z).
> >
> > I am trying to modify the itkBinaryFunctionImageFilter, but dont understand
> > what m_Functor ( ) function in the ThreadedGenerateData( ) function does. I
> > can see that it implements the pixel-wise addition, but where is this
> > function defined?
> >
> > Thanks in advance,
> >
> > Rashed karim
> >
> >
> > Luis Ibanez wrote:
> > >
> > >
> > > Hi Rashedk,
> > >
> > > It is very easy to create ITK filters that take two images.
> > >
> > > You may want to look first at the "itkBinaryFunctorImageFilter"
> > >
> > > This is the base class of all the filters that take two images
> > > as input and compute a pixel-wise output.
> > >
> > > You can ignore the "Functor" aspects of it, and focus on the
> > > SetInput1(), SetInput2() methods, the SetNumberOfRequiredInputs()
> > > call in the constructor.
> > >
> > > There are many other filters in ITK that take two images as input.
> > >
> > > For example:
> > >
> > > $ grep -l "RequiredInputs( 2 )" *.txx
> > > itkBinaryFunctorImageFilter.txx
> > > itkContourDirectedMeanDistanceImageFilter.txx
> > > itkContourMeanDistanceImageFilter.txx
> > > itkDirectedHausdorffDistanceImageFilter.txx
> > > itkHausdorffDistanceImageFilter.txx
> > > itkInterpolateImageFilter.txx
> > > itkNaryFunctorImageFilter.txx
> > > itkPolylineMask2DImageFilter.txx
> > > itkPolylineMaskImageFilter.txx
> > > itkSimilarityIndexImageFilter.txx
> > > itkWarpImageFilter.txx
> > > itkWarpVectorImageFilter.txx
> > >
> > >
> > > Please let us know if you encounter any problems,
> > >
> > >
> > >     Thanks
> > >
> > >
> > >         Luis
> > >
> > >
> > > ----------------
> > > rashedk wrote:
> > >> Hi everyone,
> > >>
> > >> I am trying to write my own filter. The filter will take in two images
> > >> (of
> > >> the same type) as input and output a single image. All the images are of
> > >> the
> > >> same dimensions. I was looking at Chapter 13 of the ITK software guide,
> > >> especially 13.6. I don't know how to go about extending this since I have
> > >> two images as input. I am also not sure If it would be appropriate to
> > >> derive
> > >> from ImageToImageFilter.
> > >>
> > >> Any ideas how I should go about doing this?
> > >>
> > >> Thanks in advance,
> > >> Rashed karim.
> > >>
> > >>
> > > _______________________________________________
> > > Insight-users mailing list
> > > Insight-users at itk.org
> > > http://www.itk.org/mailman/listinfo/insight-users
> > >
> > >
> >
> > --
> > View this message in context: http://www.nabble.com/Create-my-own-filter-tf4449323.html#a12746845
> > Sent from the ITK - Users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > 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
>


More information about the Insight-users mailing list