KSquare Utilities
KKB::MorphOp Class Referenceabstract

Base class for all Morphological operations. More...

#include <MorphOp.h>

+ Inheritance diagram for KKB::MorphOp:

Public Types

enum  MaskTypes : int {
  MaskTypes::CROSS3 = 0, MaskTypes::CROSS5 = 1, MaskTypes::SQUARE3 = 2, MaskTypes::SQUARE5 = 3,
  MaskTypes::SQUARE7 = 4, MaskTypes::SQUARE9 = 5, MaskTypes::SQUARE11 = 6
}
 
enum  OperationType {
  OperationType::Null, OperationType::Binarize, OperationType::BmiFiltering, OperationType::ConvexHull,
  OperationType::Dilation, OperationType::Erosion, OperationType::MaskExclude, OperationType::SobelEdgeDetection,
  OperationType::Stretcher
}
 
enum  StructureType : int { StructureType::Null, StructureType::stCross, StructureType::stSquare }
 

Public Member Functions

 MorphOp ()
 
virtual ~MorphOp ()
 
virtual OperationType Operation () const =0
 
OperationType OperationTypeFromStr (const KKB::KKStr &_operationStr)
 
KKB::KKStr OperationTypeToStr (OperationType _operation)
 
virtual RasterPtr PerformOperation (Raster const *_image)=0
 

Static Public Member Functions

static kkint32 Biases (MaskTypes mt)
 
static StructureType MaskShapes (MaskTypes mt)
 

Protected Member Functions

bool BackgroundPixel (uchar pixel) const
 
bool BackgroundPixel (kkint32 row, kkint32 col) const
 
bool ForegroundPixel (uchar pixel) const
 
bool ForegroundPixel (kkint32 row, kkint32 col) const
 
void SetSrcRaster (RasterConstPtr _srcRaster)
 

Protected Attributes

uchar backgroundPixelTH
 
uchar backgroundPixelValue
 
uchar *const * srcBlue
 
uchar const * srcBlueArea
 
bool srcColor
 
uchar *const * srcGreen
 
uchar const * srcGreenArea
 
kkint32 srcHeight
 
RasterConstPtr srcRaster
 
uchar *const * srcRed
 
uchar const * srcRedArea
 
kkint32 srcWidth
 

Static Protected Attributes

static kkint32 biases []
 
static StructureType maskShapes []
 

Detailed Description

Base class for all Morphological operations.

Creates a image where the only pixels that are passed thru are the ones that would be removed by the specified mask when a Open-Dilatation operation are performed.

Meant to be the base class to all Morphological operators.

It is assumed that all morphologocal operations will be working with a source image and returning a new modified image; the atcual operation is to be perfomed by the "PerformOperation" metho where you pass in a poiter to the source Image/ Raster. The the derived class would then call "SetSrcRaster" to intialize the base class "MorphOp" with pointers to the source image.

See also
KKB::Raster

Definition at line 44 of file MorphOp.h.

Member Enumeration Documentation

enum KKB::MorphOp::MaskTypes : int
strong
Enumerator
CROSS3 
CROSS5 
SQUARE3 
SQUARE5 
SQUARE7 
SQUARE9 
SQUARE11 

Definition at line 72 of file MorphOp.h.

72  : int
73  {
74  CROSS3 = 0,
75  CROSS5 = 1,
76  SQUARE3 = 2,
77  SQUARE5 = 3,
78  SQUARE7 = 4,
79  SQUARE9 = 5,
80  SQUARE11 = 6
81  };
Enumerator
Null 
Binarize 
BmiFiltering 
ConvexHull 
Dilation 
Erosion 
MaskExclude 
SobelEdgeDetection 
Stretcher 

Definition at line 47 of file MorphOp.h.

48  {
49  Null,
50  Binarize,
51  BmiFiltering,
52  ConvexHull,
53  Dilation,
54  Erosion,
55  MaskExclude,
56  SobelEdgeDetection,
57  Stretcher
58  };
enum KKB::MorphOp::StructureType : int
strong
Enumerator
Null 
stCross 
stSquare 

Definition at line 64 of file MorphOp.h.

64  : int
65  {
66  Null,
67  stCross,
68  stSquare
69  };

Constructor & Destructor Documentation

MorphOp::MorphOp ( )

Definition at line 73 of file MorphOp.cpp.

References backgroundPixelTH, backgroundPixelValue, srcBlue, srcBlueArea, srcColor, srcGreen, srcGreenArea, srcHeight, srcRaster, srcRed, srcRedArea, and srcWidth.

Referenced by KKB::ConvexHull::ConvexHull(), KKB::MorphOpBinarize::MorphOpBinarize(), KKB::MorphOpBmiFiltering::MorphOpBmiFiltering(), KKB::MorphOpMaskExclude::MorphOpMaskExclude(), KKB::MorphOpStretcher::MorphOpStretcher(), and KKB::MorphOpStruct::MorphOpStruct().

73  :
74  backgroundPixelTH (31),
76  srcRaster (NULL),
77  srcRedArea (NULL),
78  srcGreenArea (NULL),
79  srcBlueArea (NULL),
80  srcRed (NULL),
81  srcGreen (NULL),
82  srcBlue (NULL),
83  srcColor (false),
84  srcHeight (0),
85  srcWidth (0)
86 {
87 }
bool srcColor
Definition: MorphOp.h:122
kkint32 srcHeight
Definition: MorphOp.h:123
uchar *const * srcRed
Definition: MorphOp.h:118
kkint32 srcWidth
Definition: MorphOp.h:124
uchar const * srcBlueArea
Definition: MorphOp.h:116
uchar backgroundPixelTH
Definition: MorphOp.h:109
uchar *const * srcBlue
Definition: MorphOp.h:120
uchar backgroundPixelValue
Definition: MorphOp.h:110
uchar const * srcGreenArea
Definition: MorphOp.h:115
uchar *const * srcGreen
Definition: MorphOp.h:119
RasterConstPtr srcRaster
Definition: MorphOp.h:112
uchar const * srcRedArea
Definition: MorphOp.h:114
MorphOp::~MorphOp ( )
virtual

Definition at line 91 of file MorphOp.cpp.

92 {
93 }

Member Function Documentation

bool MorphOp::BackgroundPixel ( uchar  pixel) const
protected

Definition at line 171 of file MorphOp.cpp.

References backgroundPixelTH.

Referenced by KKB::MorphOpStruct::Fit(), KKB::MorphOpStruct::FitBackgroundCount(), and KKB::MorphOpDilation::PerformOperation().

172 {
173  return (pixel <= backgroundPixelTH);
174 } /* BackgroundPixel */
uchar backgroundPixelTH
Definition: MorphOp.h:109
bool MorphOp::BackgroundPixel ( kkint32  row,
kkint32  col 
) const
protected

Definition at line 178 of file MorphOp.cpp.

References backgroundPixelTH, srcGreen, srcHeight, and srcWidth.

181 {
182  if ((row < 0) ||
183  (row >= srcHeight) ||
184  (col < 0) ||
185  (col >= srcWidth) ||
186  (srcGreen == NULL)
187  )
188  return false;
189 
190  return (srcGreen[row][col] <= backgroundPixelTH);
191 } /* BackgroundPixel */
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 srcWidth
Definition: MorphOp.h:124
uchar backgroundPixelTH
Definition: MorphOp.h:109
uchar *const * srcGreen
Definition: MorphOp.h:119
kkint32 MorphOp::Biases ( MaskTypes  mt)
static
bool MorphOp::ForegroundPixel ( uchar  pixel) const
protected

Definition at line 195 of file MorphOp.cpp.

References backgroundPixelTH.

Referenced by KKB::MorphOpStruct::HitForegroundCount(), KKB::MorphOpDilation::PerformOperation(), and KKB::MorphOpErosion::PerformOperation().

196 {
197  return (pixel > backgroundPixelTH);
198 } /* ForegroundPixel */
uchar backgroundPixelTH
Definition: MorphOp.h:109
bool MorphOp::ForegroundPixel ( kkint32  row,
kkint32  col 
) const
protected

Definition at line 202 of file MorphOp.cpp.

References backgroundPixelTH, srcGreen, srcHeight, and srcWidth.

Referenced by KKB::ConvexHull::Store().

205 {
206  if ((row < 0) ||
207  (row >= srcHeight) ||
208  (col < 0) ||
209  (col >= srcWidth) ||
210  (srcGreen == NULL)
211  )
212  return false;
213 
214  return (srcGreen[row][col] > backgroundPixelTH);
215 } /* ForegroundPixel */
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 srcWidth
Definition: MorphOp.h:124
uchar backgroundPixelTH
Definition: MorphOp.h:109
uchar *const * srcGreen
Definition: MorphOp.h:119
StructureType MorphOp::MaskShapes ( MaskTypes  mt)
static

Definition at line 57 of file MorphOp.cpp.

References CROSS3, maskShapes, and SQUARE9.

Referenced by KKB::Raster::Erosion(), KKB::Raster::ErosionBoundary(), KKB::Raster::ErosionChanged(), and KKB::Raster::ErosionChanged1().

58 {
59  if (mt < MaskTypes::CROSS3)
60  mt = MaskTypes::CROSS3;
61 
62  else if (mt > MaskTypes::SQUARE9)
63  mt = MaskTypes::SQUARE9;
64 
65  return maskShapes[(int)mt];
66 }
static StructureType maskShapes[]
Definition: MorphOp.h:127
MorphOp::OperationType MorphOp::OperationTypeFromStr ( const KKB::KKStr _operationStr)

Definition at line 123 of file MorphOp.cpp.

References Binarize, BmiFiltering, ConvexHull, KKB::KKStr::EqualIgnoreCase(), Erosion, MaskExclude, Null, and Stretcher.

124 {
125  if (_operationStr.EqualIgnoreCase ("Stretcher"))
127 
128  else if (_operationStr.EqualIgnoreCase ("Binarize"))
130 
131  else if (_operationStr.EqualIgnoreCase ("BmiFiltering"))
133 
134  else if (_operationStr.EqualIgnoreCase ("ConvexHull"))
136 
137  else if (_operationStr.EqualIgnoreCase ("Erosion"))
138  return OperationType::Erosion;
139 
140  else if (_operationStr.EqualIgnoreCase ("MaskExclude"))
142 
143  else
144  return OperationType::Null;
145 }
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
KKB::KKStr MorphOp::OperationTypeToStr ( OperationType  _operation)

Definition at line 97 of file MorphOp.cpp.

References BmiFiltering, ConvexHull, Dilation, Erosion, MaskExclude, and Stretcher.

98 {
99  if (_operation == OperationType::Stretcher)
100  return "Stretcher";
101 
102  else if (_operation == OperationType::BmiFiltering)
103  return "BmiFiltering";
104 
105  else if (_operation == OperationType::ConvexHull)
106  return "ConvexHull";
107 
108  else if (_operation == OperationType::Dilation)
109  return "Dilation";
110 
111  else if (_operation == OperationType::Erosion)
112  return "Erosion";
113 
114  else if (_operation == OperationType::MaskExclude)
115  return "MaskExclude";
116 
117  else
118  return "NULL";
119 }
virtual RasterPtr KKB::MorphOp::PerformOperation ( Raster const *  _image)
pure virtual

Implemented in KKB::MorphOpSobel.

void MorphOp::SetSrcRaster ( RasterConstPtr  _srcRaster)
protected

Definition at line 149 of file MorphOp.cpp.

References backgroundPixelTH, KKB::Raster::BackgroundPixelTH(), backgroundPixelValue, KKB::Raster::BackgroundPixelValue(), KKB::Raster::Blue(), KKB::Raster::BlueArea(), KKB::Raster::Color(), KKB::Raster::Green(), KKB::Raster::GreenArea(), KKB::Raster::Height(), KKB::Raster::Red(), KKB::Raster::RedArea(), srcBlue, srcBlueArea, srcColor, srcGreen, srcGreenArea, srcHeight, srcRaster, srcRed, srcRedArea, srcWidth, and KKB::Raster::Width().

Referenced by KKB::ConvexHull::Filter(), KKB::MorphOpSobel::PerformOperation(), KKB::MorphOpBmiFiltering::PerformOperation(), KKB::MorphOpDilation::PerformOperation(), KKB::MorphOpErosion::PerformOperation(), KKB::MorphOpBinarize::PerformOperation(), KKB::MorphOpStretcher::PerformOperation(), KKB::MorphOpMaskExclude::PerformOperation(), and KKB::ConvexHull::PerformOperation().

150 {
151  srcRaster = _srcRaster;
152 
153  srcColor = srcRaster->Color ();
154  srcHeight = srcRaster->Height ();
155  srcWidth = srcRaster->Width ();
156 
157  backgroundPixelTH = srcRaster->BackgroundPixelTH ();
158  backgroundPixelValue = srcRaster->BackgroundPixelValue ();
159 
160  srcRedArea = srcRaster->RedArea ();
161  srcGreenArea = srcRaster->GreenArea ();
162  srcBlueArea = srcRaster->BlueArea ();
163 
164  srcRed = srcRaster->Red ();
165  srcGreen = srcRaster->Green ();
166  srcBlue = srcRaster->Blue ();
167 } /* SetSrcRaster */
bool srcColor
Definition: MorphOp.h:122
kkint32 srcHeight
Definition: MorphOp.h:123
uchar *const * srcRed
Definition: MorphOp.h:118
kkint32 srcWidth
Definition: MorphOp.h:124
uchar const * srcBlueArea
Definition: MorphOp.h:116
uchar backgroundPixelTH
Definition: MorphOp.h:109
uchar *const * srcBlue
Definition: MorphOp.h:120
uchar backgroundPixelValue
Definition: MorphOp.h:110
uchar const * srcGreenArea
Definition: MorphOp.h:115
uchar *const * srcGreen
Definition: MorphOp.h:119
RasterConstPtr srcRaster
Definition: MorphOp.h:112
uchar const * srcRedArea
Definition: MorphOp.h:114

Member Data Documentation

uchar KKB::MorphOp::backgroundPixelTH
protected

Definition at line 109 of file MorphOp.h.

Referenced by BackgroundPixel(), ForegroundPixel(), MorphOp(), and SetSrcRaster().

uchar KKB::MorphOp::backgroundPixelValue
protected

Definition at line 110 of file MorphOp.h.

Referenced by MorphOp(), and SetSrcRaster().

kkint32 MorphOp::biases
staticprotected
Initial value:
= {1,
2,
1,
2,
3,
4,
5
}

Definition at line 126 of file MorphOp.h.

Referenced by Biases().

StructureType MorphOp::maskShapes
staticprotected
uchar* const* KKB::MorphOp::srcBlue
protected

Definition at line 120 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpStretcher::PerformOperation(), and SetSrcRaster().

uchar const* KKB::MorphOp::srcBlueArea
protected

Definition at line 116 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpMaskExclude::PerformOperation(), and SetSrcRaster().

bool KKB::MorphOp::srcColor
protected

Definition at line 122 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpMaskExclude::PerformOperation(), and SetSrcRaster().

uchar const* KKB::MorphOp::srcGreenArea
protected

Definition at line 115 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpMaskExclude::PerformOperation(), and SetSrcRaster().

uchar* const* KKB::MorphOp::srcRed
protected

Definition at line 118 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpStretcher::PerformOperation(), and SetSrcRaster().

uchar const* KKB::MorphOp::srcRedArea
protected

Definition at line 114 of file MorphOp.h.

Referenced by MorphOp(), KKB::MorphOpMaskExclude::PerformOperation(), and SetSrcRaster().


The documentation for this class was generated from the following files: