[Insight-users] image filter ThresholdInside?

Luis Ibanez luis.ibanez at kitware.com
Sun Oct 14 14:20:46 EDT 2007


Hi Sharath,

If your Functor is expected to have parameters, then you can add
then to the Functor class, and then you can create a filter that
derives from the itk::UnaryFunctorImageFilter, in which you also
expose the Functor parameters.

Please look at the code of the itkBinaryThresholdImageFilter for
an example on how to add parameters to functors and to Filters.


    Regards,


       Luis



------------------------
Sharath Cholleti wrote:
> Thanks Luis. Good to know about itkUnaryFunctorImageFilter.
> 
> The example I gave was specific but that was just a one time 
> requirement. In general, I want to give a range, lets say 120-165, and 
> change the values in this range to some x. According to my understanding 
> the functions in ThresholdImageFilter (for example, ThresholdOutside()) 
> and BinaryThresholdImageFilter classes changed the values outside the 
> given range. Is that right or am I missing some way of changing the 
> values inside the range?
> 
> Is using itkUnaryFunctorImageFilter the best way to go about if I want 
> to make a general ThresholdInside() function? If have that then I can 
> very easily solve my original example plus more.
> 
> Thanks again.
> 
> -Sharath
> 
> On 10/12/07, *Luis Ibanez* <luis.ibanez at kitware.com 
> <mailto:luis.ibanez at kitware.com>> wrote:
> 
> 
>     Hi Sharath,
> 
>     The Thresholding filter that you need is too specific and doesn't
>     match the profile of any of the filters we currently have.
> 
>     However, it will be *very* easy for you to write one by taking
>     advantage of the itkUnaryFunctorImageFilter.
> 
>     You just need to write a Functor, and then instantiate the
>     itkUnaryFunctorImageFilter over the input image, output image
>     and the functor.
> 
> 
>     The functor that you need will look like:
>     (asumming that your images are using "unsigned char" pixel type).
> 
> 
>     namespace Functor {
> 
>     class MyThreshold
>     {
>     public:
>        MyThreshold() {};
>        ~MyThreshold() {};
> 
>        bool operator!=( const BinaryThreshold & other ) const
>          { return false; }
>        bool operator==( const BinaryThreshold & other ) const
>          { return !(*this != other); }
> 
>        inline unsigned char operator()( const unsigned char & A )
>        {
>          if ( A ==   0 ) { return   0; }
>          if ( A == 255 ) { return 255; }
>          if ( A <  127 ) { return 255; }
>          return 0;
>        }
>     private:
>     };
>     }
> 
> 
>     Then you can instantiate:
> 
> 
>     typedef itk::UnaryFunctorImageFilter<
>        InputImageType, OutputImageType, Functor::MyThreshod > FilterType;
> 
>     FilterType::Pointer filter = FilterType::New();
> 
> 
> 
> 
>         Regards,
> 
> 
>            Luis
> 
> 
> 
>     -----------------------
>     Sharath Cholleti wrote:
>      > Hi,
>      >
>      > I am new to ITK and started reading parts of the software guide as
>      > required.
>      >
>      > I need to change the pixel values of an image to 255 if its value is
>      > between 1-127 and to 0 if its value is between 128-254. Keep all
>     pixels
>      > of 0 and 255's as they are. I noticed ThresholdOutside function in
>      > ThresholdImageFilter but in a way I need a "ThresholdInside"
>     function.  Is
>      > there such a function that would allow me to do this?
>      >
>      > I looked at BinaryThresholdImageFilter and ThresholdImageFilter
>      > classes for this particular problem.
>      >
>      > Thanks,
>      >
>      > Sharath
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      >
>      > _______________________________________________
>      > Insight-users mailing list
>      > Insight-users at itk.org <mailto:Insight-users at itk.org>
>      > http://www.itk.org/mailman/listinfo/insight-users
> 
> 


More information about the Insight-users mailing list