| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSobelOperator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
|
| 18 |
|
#ifndef __itkSobelOperator_h |
| 19 |
|
#define __itkSobelOperator_h |
| 20 |
|
|
| 21 |
|
#include "itkExceptionObject.h" |
| 22 |
|
#include "itkNeighborhoodOperator.h" |
| 23 |
|
|
| 24 |
|
namespace itk { |
| 25 |
|
|
| 26 |
|
/** |
| 27 |
|
* \class SobelOperator |
| 28 |
|
* |
| 29 |
|
* \brief A NeighborhoodOperator for performing a directional Sobel |
| 30 |
|
* edge-detection operation * at a pixel location. |
| 31 |
|
* |
| 32 |
|
* SobelOperator is a directional NeighborhoodOperator that should be |
| 33 |
|
* applied a NeighborhoodIterator using the NeighborhoodInnerProduct |
| 34 |
|
* method. To create the operator: |
| 35 |
|
* |
| 36 |
|
* 1) Set the direction by calling \code{SetDirection} |
| 37 |
|
* 2) call \code{CreateOperator()} |
| 38 |
|
* 3) You may optionally scale the coefficients of this operator using the |
| 39 |
|
* \code{ScaleCoefficients} method. This is useful if you want to take the |
| 40 |
|
* spacing of the image into account when computing the edge strength. Apply |
| 41 |
|
* the scaling only after calling to \code{CreateOperator}. |
| 42 |
|
* |
| 43 |
|
* The Sobel Operator in vertical direction for 2 dimensions is |
| 44 |
|
* \verbatim |
| 45 |
|
* -1 -2 -1 |
| 46 |
|
* 0 0 0 |
| 47 |
|
* 1 2 1 |
| 48 |
|
* |
| 49 |
|
* \endverbatim |
| 50 |
|
* The Sobel Operator in horizonal direction is for 2 dimensions is |
| 51 |
|
* \verbatim |
| 52 |
|
* -1 0 1 |
| 53 |
|
* -2 0 2 |
| 54 |
|
* -1 0 1 |
| 55 |
|
* \endverbatim |
| 56 |
|
* |
| 57 |
LEN |
* The current implementation of the Sobel operator is for 2 and 3 dimensions only. |
| 58 |
|
* The ND version is planned for future releases. |
| 59 |
|
* |
| 60 |
|
* The extension to 3D is from the publication |
| 61 |
|
* "Irwin Sobel. An Isotropic 3x3x3 Volume Gradient Operator. |
| 62 |
|
* Technical report, Hewlett-Packard Laboratories, April 1995." |
| 63 |
|
* |
| 64 |
|
* The Sobel operator in 3D has the kernel |
| 65 |
|
* |
| 66 |
|
* \verbatim |
| 67 |
|
* -1 -3 -1 0 0 0 1 3 1 |
| 68 |
|
* -3 -6 -3 0 0 0 3 6 3 |
| 69 |
|
* -1 -3 -1 0 0 0 1 3 1 |
| 70 |
|
* |
| 71 |
|
* x-1 x x+1 |
| 72 |
|
* \endverbatim |
| 73 |
|
* |
| 74 |
|
* The \code{x} kernel is just rotated as required to obtain the kernel in the |
| 75 |
|
* \code{y} and \code{z} directions. |
| 76 |
|
* |
| 77 |
|
* \sa NeighborhoodOperator |
| 78 |
|
* \sa Neighborhood |
| 79 |
|
* \sa ForwardDifferenceOperator |
| 80 |
|
* \sa BackwardDifferenceOperator |
| 81 |
|
* |
| 82 |
|
* \ingroup Operators |
| 83 |
|
*/ |
| 84 |
|
template<class TPixel, unsigned int VDimension=2, |
| 85 |
|
class TAllocator = NeighborhoodAllocator<TPixel> > |
| 86 |
|
class ITK_EXPORT SobelOperator |
| 87 |
IND |
**: public NeighborhoodOperator<TPixel, VDimension, TAllocator> |
| 88 |
|
{ |
| 89 |
|
public: |
| 90 |
|
/** Standard typedefs */ |
| 91 |
|
typedef SobelOperator Self; |
| 92 |
TDA |
typedef NeighborhoodOperator<TPixel, VDimension, TAllocator> Superclass; |
| 93 |
|
|
| 94 |
|
itkTypeMacro(SobelOperator, NeighborhoodOperator); |
| 95 |
|
|
| 96 |
|
SobelOperator() {} |
| 97 |
|
SobelOperator(const Self& other) |
| 98 |
IND |
****: NeighborhoodOperator<TPixel, VDimension, TAllocator>(other) |
| 99 |
IND |
**{ } |
| 100 |
|
|
| 101 |
|
/** Creates the operator with length only in the specified direction. For |
| 102 |
|
* the Sobel operator, this |
| 103 |
|
* The radius of the operator will be 0 except along the axis on which |
| 104 |
|
* the operator will work. |
| 105 |
LEN |
* \sa CreateToRadius \sa FillCenteredDirectional \sa SetDirection() \sa GetDirection() */ |
| 106 |
|
virtual void CreateDirectional() |
| 107 |
IND |
**{ |
| 108 |
|
this->CreateToRadius(1); |
| 109 |
IND |
**} |
| 110 |
|
|
| 111 |
|
/** Creates the operator with a specified radius ("square", same length |
| 112 |
|
* on each side). The spatial location of the coefficients within the |
| 113 |
|
* operator is defined by the subclass implementation of the Fill method. |
| 114 |
|
* \sa CreateDirectional \sa Fill */ |
| 115 |
|
// virtual void CreateToRadius(const unsigned long); |
| 116 |
|
/** |
| 117 |
|
* Assignment operator |
| 118 |
|
*/ |
| 119 |
|
Self &operator=(const Self& other) |
| 120 |
IND |
**{ |
| 121 |
|
Superclass::operator=(other); |
| 122 |
|
return *this; |
| 123 |
IND |
**} |
| 124 |
|
/** |
| 125 |
|
* Prints some debugging information |
| 126 |
|
*/ |
| 127 |
|
virtual void PrintSelf(std::ostream &os, Indent i) const |
| 128 |
IND |
**{ |
| 129 |
|
os << i << "SobelOperator { this=" << this << "}" << std::endl; |
| 130 |
|
Superclass::PrintSelf(os, i.GetNextIndent()); |
| 131 |
IND |
**} |
| 132 |
|
|
| 133 |
|
protected: |
| 134 |
|
/** |
| 135 |
|
* Typedef support for coefficient vector type. Necessary to |
| 136 |
|
* work around compiler bug on VC++. |
| 137 |
|
*/ |
| 138 |
|
typedef typename Superclass::CoefficientVector CoefficientVector; |
| 139 |
TDA |
typedef typename Superclass::PixelType PixelType; |
| 140 |
|
|
| 141 |
|
/** |
| 142 |
|
* Calculates operator coefficients. |
| 143 |
|
*/ |
| 144 |
|
CoefficientVector GenerateCoefficients(); |
| 145 |
|
|
| 146 |
|
/** |
| 147 |
|
* Arranges coefficients spatially in the memory buffer. |
| 148 |
|
*/ |
| 149 |
|
void Fill(const CoefficientVector &c); |
| 150 |
|
|
| 151 |
|
}; |
| 152 |
|
|
| 153 |
|
} // namespace itk |
| 154 |
|
|
| 155 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 156 |
|
#include "itkSobelOperator.txx" |
| 157 |
|
#endif |
| 158 |
|
|
| 159 |
|
#endif |
| 160 |
|
|
| 161 |
EOF |
|
| 162 |
EOF,EML |
|