[ITK Community] [Insight-users] Problem first filter write on my own

Matt McCormick matt.mccormick at kitware.com
Sat Jan 4 14:31:17 EST 2014


Hi Alessio,

If creating something that inherits from ProcessObject, which
ImageToImageFilter does indirectly, it is intended to be used in a
processing pipeline.  In this case the computation of the pixel value
would occur in the virtual GenerateData() method.  It would be
executed like this:

  filter->SetInput( image );
  filter->Update();
  std::cout << filter->GetPixelOfImage();

For lighter weight operations like that do not create an output image
and are not intended to be in a pipeline, look at some of the
"Calculator" classes.  It is executed like;

  reader->Update();
  filter->SetInput( reader->GetOutput() );
  filter->Compute(); // does not do a pipeline update, so the image
must be available
  std::cout << filter->GetPixelOfImage();

Hope this helps,
Matt

On Sat, Jan 4, 2014 at 10:40 AM, Alessio Mazzarini
<alessiomazzarini89 at gmail.com> wrote:
> Hi everyone, i'm trying to understand how to write my own filter and i
> started with a simple one.
> I would like to create a simple filter that takes as input an image and then
> shows on terminal the value of a pixel (defined in the constructor method).
> For simplicity i reused the ImageToImageFilter class (obv there will be a
> better way to do it) without set any output image. This is my code:
>
>
> ********************** takePixel.h******************************
> #ifndef __takePixel_h
> #define __takePixel_h
>
>
> #include "itkImageToImageFilter.h"
>
> namespace itk
> {
>
> template  < typename TInputImage, typename TOutputImage >
> class takePixel :
>   public ImageToImageFilter < TInputImage, TOutputImage >
> {
> public:
>   /** Standard class typedefs. */
>   typedef takePixel                        Self;
>   typedef ImageToImageFilter < TInputImage, TOutputImage > Superclass;
>   typedef SmartPointer < Self > Pointer;
>   typedef SmartPointer < const Self > ConstPointer;
>
>   /** Method for creation through the object factory. */
>   itkNewMacro(Self);
>
>
>   /** Typedef for images */
>   typedef TInputImage                            InputImageType;
>   typedef TOutputImage OutputImageType;
>   typedef typename TInputImage::IndexType       IndexType;
>   typedef typename OutputImageType::Pointer OutputImagePointer;
>   typedef typename InputImageType::Pointer InputImagePointer;
>   typedef typename InputImageType::ConstPointer InputImageConstPointer;
>   typedef typename TInputImage::PixelType    PixelType;
>
>
> protected:
>   takePixel();
>   virtual ~takePixel() {};
>   void PrintSelf(std::ostream & os, Indent indent) const;
>
>
>
>   void GetPixelOfImage();  //Method of the filter, to get PixelValue
>
> private:
>   takePixel(const Self &); //purposely not implemented
>   void operator=(const Self &);          //purposely not implemented
>   PixelType pixelA;
>   IndexType indexA;
>
> };
> } // end namespace itk
>
> #ifndef ITK_MANUAL_INSTANTIATION
> #include "takePixel.hxx"
> #endif
>
> #endif
> ***********************************************************************************
>
> ***************************************takePixel.hxx*********************************************
> #ifndef __takePixel_hxx
> #define __takePixel_hxx
>
> #include "takePixel.h"
> #include <iostream>
>
> namespace itk
> {
>     //Constructor that set the pixel index
> template  < typename TInputImage, typename TOutputImage >
> takePixel < TInputImage, TOutputImage >
> ::takePixel ()
> {
>     indexA[0]=10;
>     indexA[1]=10;
>   itkDebugMacro(<< "takePixel::takePixel() called");
>
> }
>
>
> template< typename TInputImage, typename TOutputImage >
> void
> takePixel < TInputImage, TOutputImage >
> ::GetPixelOfImage()
> {
>              InputImageConstPointer inputPtr  = this->GetInput(0);
>           pixelA = inputPtr->GetPixel(indexA);
>        this->Modified();
> std::cout<<"Pixel value: "<<pixelA<<std::endl;
> //return pixelA;
> }
>
>
> template< typename TInputImage, typename TOutputImage >
> void
> takePixel < TInputImage, TOutputImage >
> ::PrintSelf(std::ostream & os, Indent indent) const
> {
>   Superclass::PrintSelf(os, indent);
> os << indent << "Value of Pixel: " << pixelA << std::endl;
> }
> } // end namespace
>
> #endif
>
>
>
> Where am I doing wrong in writing this filter? Any help is much appreciated.
> Is there any filter that takes as input an image and doesn't return
> anyoutput image that I can use as a reference?
>
> Regards,
> Alessio
>
> _____________________________________
> 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
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community
_____________________________________
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 Community mailing list