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

Alessio Mazzarini alessiomazzarini89 at gmail.com
Sat Jan 4 10:40:24 EST 2014


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



More information about the Community mailing list