[Insight-users] AND/OR operation and structuring element
Luis Ibanez
luis . ibanez at kitware . com
Thu, 04 Dec 2003 10:33:36 -0500
This is a multi-part message in MIME format.
--------------010900030500080302000304
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi Radhika,
You can easily create any new pixel-wise filter
by using the Unary/Binary/Ternary Functor filters.
For the OR operation you simply need to create
a Functor object defining the OR operation and
then use it to instantiate a BinaryFunctor filter.
The code for an OR filter is attached.
From this attached code you can get a AND filter just
by changing one line of code and renaming the filter.
Please let us know if you find any difficulties.
Thanks
Luis
---------------------------------
Radhika Sivaramakrishna wrote:
> Hi Luiz,
>
> Thanks for your earlier responses.
> I had the following questions:
>
> 1) Given two binary masks, what are the available functions to do an AND
> or an OR of these two masks? I see a filter BinaryFunctorImageFilter but
> do not know how to use this.
>
> 2) I want to specify my own structuring element with the mathematical
> morphology filters, which is a 3x3x3 with
> 1's only in the nearest neighbor positions and 0's in the off-diagonal
> places. How do I do this? i.e. I know how to call the standard
> BallStructuring element, but I don't know how to edit it.
>
> Thanks
> Radhika
>
--------------------------------------------------------------------
---------------------------------------------------------------------
--------------010900030500080302000304
Content-Type: text/plain;
name="itkOrImageFilter.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="itkOrImageFilter.h"
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkOrImageFilter.h,v $
Language: C++
Date: $Date: 2003/09/10 14:28:43 $
Version: $Revision: 1.7 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www . itk . org/HTML/Copyright . htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkOrImageFilter_h
#define __itkOrImageFilter_h
#include "itkBinaryFunctorImageFilter.h"
#include "itkNumericTraits.h"
namespace itk
{
/** \class OrImageFilter
* \brief Implements the OR logical operator pixel-wise between two images.
*
* This class is parametrized over the types of the two
* input images and the type of the output image.
* Numeric conversions (castings) are done by the C++ defaults.
*
* Since the logical OR operation is only defined in C++ for integer
* types, the images passed to this filter must comply with the requirement
* of using integer pixel type.
*
* The total operation over one pixel will be
*
* output_pixel = static_cast<OutputPixelType>( input1_pixel | input2_pixel )
*
* Where "|" is the boolean OR operator in C++.
*
* \ingroup IntensityImageFilters Multithreaded
*/
namespace Functor {
template< class TInput1, class TInput2=TInput1, class TOutput=TInput1 >
class OR
{
public:
OR() {};
~OR() {};
inline TOutput operator()( const TInput1 & A, const TInput2 & B)
{
return static_cast<TOutput>( A | B );
}
};
}
template <class TInputImage1, class TInputImage2, class TOutputImage>
class ITK_EXPORT OrImageFilter :
public
BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
Functor::OR<
typename TInputImage1::PixelType,
typename TInputImage2::PixelType,
typename TOutputImage::PixelType> >
{
public:
/** Standard class typedefs. */
typedef OrImageFilter Self;
typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
Functor::OR<
typename TInputImage1::PixelType,
typename TInputImage2::PixelType,
typename TOutputImage::PixelType>
> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
protected:
OrImageFilter() {}
virtual ~OrImageFilter() {}
private:
OrImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
} // end namespace itk
#endif
--------------010900030500080302000304--