KSquare Utilities
MorphOp.h
Go to the documentation of this file.
1 /* MorphOp.h -- Works with Raster class to track individual connected component in Raster.
2  * Copyright (C) 1994-2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 
6 #ifndef _MORPHOP_
7 #define _MORPHOP_
8 /**
9  *@class KKB::MorphOp
10  *@brief Meant to be the base class to all Morphological operators.
11  *
12  *@details
13  *
14  *@see KKB::Raster
15  */
16 
17 
18 
19 #include "KKQueue.h"
20 #include "KKStr.h"
21 #include "RunLog.h"
22 
23 
24 #if !defined(_Raster_Defined_)
25 namespace KKB
26 {
27  class Raster;
28  typedef Raster* RasterPtr;
29  typedef Raster const* RasterConstPtr;
30 }
31 
32 #endif
33 
34 namespace KKB
35 {
36  /**
37  *@brief Base class for all Morphological operations.
38  *@details
39  * It is assumed that all morphologocal operations will be working with a source image and returning a new
40  * modified image; the atcual operation is to be perfomed by the "PerformOperation" metho where you pass in
41  * a poiter to the source Image/ Raster. The the derived class would then call "SetSrcRaster" to intialize
42  * the base class "MorphOp" with pointers to the source image.
43  */
44  class MorphOp
45  {
46  public:
47  enum class OperationType
48  {
49  Null,
50  Binarize,
52  ConvexHull,
53  Dilation,
54  Erosion,
57  Stretcher
58  };
59 
61  OperationType OperationTypeFromStr (const KKB::KKStr& _operationStr);
62 
63 
64  enum class StructureType: int
65  {
66  Null,
67  stCross,
68  stSquare
69  };
70 
71 
72  enum class MaskTypes: int
73  {
74  CROSS3 = 0,
75  CROSS5 = 1,
76  SQUARE3 = 2,
77  SQUARE5 = 3,
78  SQUARE7 = 4,
79  SQUARE9 = 5,
80  SQUARE11 = 6
81  };
82 
83  MorphOp ();
84 
85  virtual ~MorphOp ();
86 
87  virtual OperationType Operation () const = 0;
88 
89  virtual RasterPtr PerformOperation (Raster const* _image) = 0;
90 
91  static kkint32 Biases (MaskTypes mt);
93 
94  protected:
95  bool BackgroundPixel (uchar pixel) const;
96 
97  bool BackgroundPixel (kkint32 row,
98  kkint32 col
99  ) const;
100 
101  bool ForegroundPixel (uchar pixel) const;
102 
103  bool ForegroundPixel (kkint32 row,
104  kkint32 col
105  ) const;
106 
107  void SetSrcRaster (RasterConstPtr _srcRaster);
108 
111 
112  RasterConstPtr srcRaster;
113 
117 
118  uchar* const* srcRed;
119  uchar* const* srcGreen;
120  uchar* const* srcBlue;
121 
122  bool srcColor;
125 
126  static kkint32 biases[];
128 
129  private:
130  }; /* MorphOp */
131 
132 #define _MorphOp_Defined_
133 
134  typedef MorphOp* MorphOpPtr;
135 
137 
139 } /* namespace KKB; */
140 
141 #endif
Raster * RasterPtr
Definition: BMPImage.h:25
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
static kkint32 biases[]
Definition: MorphOp.h:126
__int32 kkint32
Definition: KKBaseTypes.h:88
MorphOp * MorphOpPtr
Definition: MorphOp.h:134
OperationType OperationTypeFromStr(const KKB::KKStr &_operationStr)
Definition: MorphOp.cpp:123
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
bool BackgroundPixel(uchar pixel) const
Definition: MorphOp.cpp:171
static StructureType MaskShapes(MaskTypes mt)
Definition: MorphOp.cpp:57
MorphologicalOperatorList * MorphologicalOperatorListPtr
Definition: MorphOp.h:138
static kkint32 Biases(MaskTypes mt)
Definition: MorphOp.cpp:44
bool srcColor
Definition: MorphOp.h:122
kkint32 srcHeight
Definition: MorphOp.h:123
KKTHread * KKTHreadPtr
KKQueue< MorphOp > MorphologicalOperatorList
Definition: MorphOp.h:136
bool ForegroundPixel(kkint32 row, kkint32 col) const
Definition: MorphOp.cpp:202
uchar *const * srcRed
Definition: MorphOp.h:118
kkint32 srcWidth
Definition: MorphOp.h:124
uchar const * srcBlueArea
Definition: MorphOp.h:116
virtual OperationType Operation() const =0
A typed container class/template that keeps track of entries via pointers only.
Definition: KKQueue.h:77
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual RasterPtr PerformOperation(Raster const *_image)=0
KKB::KKStr OperationTypeToStr(OperationType _operation)
Definition: MorphOp.cpp:97
uchar backgroundPixelTH
Definition: MorphOp.h:109
uchar *const * srcBlue
Definition: MorphOp.h:120
virtual ~MorphOp()
Definition: MorphOp.cpp:91
uchar backgroundPixelValue
Definition: MorphOp.h:110
static StructureType maskShapes[]
Definition: MorphOp.h:127
uchar const * srcGreenArea
Definition: MorphOp.h:115
Base class for all Morphological operations.
Definition: MorphOp.h:44
bool BackgroundPixel(kkint32 row, kkint32 col) const
Definition: MorphOp.cpp:178
uchar *const * srcGreen
Definition: MorphOp.h:119
RasterConstPtr srcRaster
Definition: MorphOp.h:112
uchar const * srcRedArea
Definition: MorphOp.h:114
bool ForegroundPixel(uchar pixel) const
Definition: MorphOp.cpp:195