[Insight-users] coloreg region segmentation

Luis Ibanez luis.ibanez@kitware.com
Wed, 27 Nov 2002 12:14:27 -0500


Hi Mathieu,


Please correct me if I'm wrong here:

1) Your images are represented with RGBPixel<>s.

2) In the same image there are pixels whose three
    RGB components are the same (those are the gray
    pixels) and there are others with different values
    on each components (those are the doppler zones).

3) Your goal is to identify pixels in the boundary
    between the colored regions and the grayscale
    regions.


Question:

Are the colored regions homogeneous or do they have
continuos grades of colors ?
(I guess the second case is what you use in doppler US).

Do you care about separating the colored region among
themselves of just to separate color from grayscale ?


-----


How about cheating ?
I mean, using heuristics   :-)


You can simply build a modified version of the
BinaryThresholdImageFilter by providing a functor
that returns 0 when the RGB components are the same
and 1 (or 255) when they are not. The output of this
filter will be a binary image with the colored regions
in 1 (or 255) and the grayscale regions in 0.

Please take a look at the files:

      itkBinaryThresholdImageFilter.h
      itkBinaryThresholdImageFilter.txx

in

      Insight/Code/BasicFilters/


This filter derives from the UnaryFunctorImageFilter
which applies a pixel-wise operation to all the pixels
in your image. You only need to define the operation
through the creation of a Functor class.

The functor class is then used as template parameter
for the instantiation of the filter.

The nice thing with this filter is that you get
multithreading for free  :-)

This is how all the pixel-wise filters are implemented
in ITK.



The functor you need, may look like:


namespace Functor {

   template< class TInput, class TOutput>
   class ColorGrayDiscriminatorFunctor
   {
   public:
     ColorGrayDiscriminatorFunctor() {};
     ~ColorGrayDiscriminatorFunctor() {};
     inline TOutput operator()( const TInput & A )
     {
       if ( A.GetRed() != A.GetBlue()   ||
            A.GetRed() != A.GetGreen()     )
         {
         return static_cast<TOutput>( 255 );
         }
       return static_cast<TOutput>( 0 );
     }
   };

} // end of namespace functor.




Then the filter should look like:





template <class TInputImage, class TOutputImage>
class ITK_EXPORT ColoGrayDiscriminatorImageFilter :
     public
     UnaryFunctorImageFilter<TInputImage,TOutputImage,
     Functor::ColorGrayDiscriminatorFunctor<
               typename TInputImage::PixelType,
               typename TOutputImage::PixelType> >
{
public:
   /** Standard class typedefs. */
   typedef ColoGrayDiscriminatorImageFilter  Self;
   typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
     Functor::ColorGrayDiscriminatorFunctor<
               typename TInputImage::PixelType,
               typename TOutputImage::PixelType>
                 >  Superclass;
   typedef SmartPointer<Self>   Pointer;
   typedef SmartPointer<const Self>  ConstPointer;

... etc..



Please let us know if you have further questions.



   Thanks


     Luis



===================================================

Mathieu Lamard wrote:

> Hi Luis
> 
> Thanks fot your prompt answers
> 
> In fact my images are RGB images but all pixels except doppler zone are 
> grey (R=G=B).
> The segmentation is easy to do. But I am looking for the main framework 
> to do that. What classes have I to use  : itkRegion,... ?
> The goal is to get the contour of each colored region as fast as possible.
> One other thing is that I know one point in each region. So I think that 
> I have to perform a growing region.
> What do you think about that ?
> 
> Mathieu
> 
> 
>