KSquare Utilities
KKB::MorphOpStruct Class Referenceabstract

#include <MorphOpStruct.h>

+ Inheritance diagram for KKB::MorphOpStruct:

Public Member Functions

 MorphOpStruct (StructureType _structure, kkuint16 _structureSize)
 
virtual ~MorphOpStruct ()
 
void BackgroundCountTH (kkint32 _backgroundCountTH)
 
void ForegroundCountTH (kkint32 _foregroundCountTH)
 
kkint32 MemoryConsumedEstimated ()
 
virtual OperationType Operation () const
 
virtual RasterPtr PerformOperation (RasterConstPtr _image)=0
 
- Public Member Functions inherited from KKB::MorphOp
 MorphOp ()
 
virtual ~MorphOp ()
 
OperationType OperationTypeFromStr (const KKB::KKStr &_operationStr)
 
KKB::KKStr OperationTypeToStr (OperationType _operation)
 
virtual RasterPtr PerformOperation (Raster const *_image)=0
 

Protected Member Functions

bool Fit (kkint32 row, kkint32 col) const
 
bool FitBackgroundCount (kkint32 row, kkint32 col) const
 
uchar HitForegroundCount (kkint32 row, kkint32 col) const
 
- Protected Member Functions inherited from KKB::MorphOp
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

kkint32 backgroundCountTH
 
kkint32 foregroundCountTH
 
StructureType structure
 
kkuint16 structureSize
 
- Protected Attributes inherited from KKB::MorphOp
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
 

Additional Inherited Members

- Public Types inherited from KKB::MorphOp
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 }
 
- Static Public Member Functions inherited from KKB::MorphOp
static kkint32 Biases (MaskTypes mt)
 
static StructureType MaskShapes (MaskTypes mt)
 
- Static Protected Attributes inherited from KKB::MorphOp
static kkint32 biases []
 
static StructureType maskShapes []
 

Detailed Description

Definition at line 24 of file MorphOpStruct.h.

Constructor & Destructor Documentation

MorphOpStruct::MorphOpStruct ( StructureType  _structure,
kkuint16  _structureSize 
)

Definition at line 21 of file MorphOpStruct.cpp.

References backgroundCountTH, foregroundCountTH, KKB::MorphOp::MorphOp(), structure, and structureSize.

Referenced by KKB::MorphOpDilation::MorphOpDilation(), and KKB::MorphOpErosion::MorphOpErosion().

23  :
24  MorphOp (),
27  structure (_structure),
28  structureSize (_structureSize)
29 {
30 }
kkuint16 structureSize
Definition: MorphOpStruct.h:59
kkint32 backgroundCountTH
Definition: MorphOpStruct.h:57
StructureType structure
Definition: MorphOpStruct.h:56
kkint32 foregroundCountTH
Definition: MorphOpStruct.h:58
MorphOpStruct::~MorphOpStruct ( )
virtual

Definition at line 34 of file MorphOpStruct.cpp.

35 {
36 }

Member Function Documentation

void KKB::MorphOpStruct::BackgroundCountTH ( kkint32  _backgroundCountTH)
inline

Definition at line 39 of file MorphOpStruct.h.

References backgroundCountTH.

Referenced by KKB::Raster::Erosion().

39 {backgroundCountTH = _backgroundCountTH;}
kkint32 backgroundCountTH
Definition: MorphOpStruct.h:57
bool MorphOpStruct::Fit ( kkint32  row,
kkint32  col 
) const
protected

Definition at line 49 of file MorphOpStruct.cpp.

References KKB::MorphOp::BackgroundPixel(), KKB::MorphOp::srcGreen, KKB::MorphOp::srcHeight, KKB::MorphOp::srcWidth, structure, structureSize, and KKB::MorphOp::stSquare.

Referenced by KKB::MorphOpErosion::PerformOperation().

52 {
53  kkint32 r, c;
54  kkint32 rStart = row - structureSize;
55  kkint32 rEnd = row + structureSize;
56  kkint32 cStart = col - structureSize;
57  kkint32 cEnd = col + structureSize;
58 
59  if (rStart < 0) rStart = 0;
60  if (rEnd >= srcHeight) rEnd = srcHeight - 1;
61  if (cStart < 0) cStart = 0;
62  if (cEnd >= srcWidth) cEnd = srcWidth - 1;
63 
65  {
66  for (r = rStart; r <= rEnd; r++)
67  {
68  uchar const* rowPtr = srcGreen[r];
69 
70  for (c = cStart; c <= cEnd; c++)
71  {
72  if (BackgroundPixel (rowPtr[c]))
73  return false;
74  }
75  }
76  }
77 
78  else
79  {
80  for (r = rStart; r <= rEnd; r++)
81  {
82  if (BackgroundPixel (srcGreen[r][col]))
83  return false;
84  }
85 
86  for (c = cStart; c <= cEnd; c++)
87  {
88  if (BackgroundPixel (srcGreen[row][c]))
89  return false;
90  }
91  }
92 
93  return true;
94 } /* Fit */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkuint16 structureSize
Definition: MorphOpStruct.h:59
bool BackgroundPixel(uchar pixel) const
Definition: MorphOp.cpp:171
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
StructureType structure
Definition: MorphOpStruct.h:56
uchar *const * srcGreen
Definition: MorphOp.h:119
bool MorphOpStruct::FitBackgroundCount ( kkint32  row,
kkint32  col 
) const
protected

Definition at line 99 of file MorphOpStruct.cpp.

References backgroundCountTH, KKB::MorphOp::BackgroundPixel(), KKB::MorphOp::srcGreen, KKB::MorphOp::srcHeight, KKB::MorphOp::srcWidth, structure, structureSize, and KKB::MorphOp::stSquare.

Referenced by KKB::MorphOpErosion::PerformOperation().

102 {
103  kkint32 r, c;
104  kkint32 rStart = row - structureSize;
105  kkint32 rEnd = row + structureSize;
106  kkint32 cStart = col - structureSize;
107  kkint32 cEnd = col + structureSize;
108 
109  if (rStart < 0) rStart = 0;
110  if (rEnd >= srcHeight) rEnd = srcHeight - 1;
111  if (cStart < 0) cStart = 0;
112  if (cEnd >= srcWidth) cEnd = srcWidth - 1;
113 
114  int backgroundCount = 0;
115 
117  {
118  for (r = rStart; r <= rEnd; r++)
119  {
120  uchar const* rowPtr = srcGreen[r];
121 
122  for (c = cStart; c <= cEnd; c++)
123  {
124  if (BackgroundPixel (rowPtr[c]))
125  ++backgroundCount;
126  }
127  }
128  }
129 
130  else
131  {
132  for (r = rStart; r <= rEnd; r++)
133  {
134  if (BackgroundPixel (srcGreen[r][col]))
135  ++backgroundCount;
136  }
137 
138  for (c = cStart; c <= cEnd; c++)
139  {
140  if (BackgroundPixel (srcGreen[row][c]))
141  ++backgroundCount;
142  }
143  }
144 
145  return backgroundCount < backgroundCountTH;
146 } /* FitBackgroundCount */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkuint16 structureSize
Definition: MorphOpStruct.h:59
bool BackgroundPixel(uchar pixel) const
Definition: MorphOp.cpp:171
kkint32 backgroundCountTH
Definition: MorphOpStruct.h:57
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
StructureType structure
Definition: MorphOpStruct.h:56
uchar *const * srcGreen
Definition: MorphOp.h:119
void KKB::MorphOpStruct::ForegroundCountTH ( kkint32  _foregroundCountTH)
inline

Definition at line 40 of file MorphOpStruct.h.

References foregroundCountTH.

Referenced by KKB::Raster::Dilation().

40 {foregroundCountTH = _foregroundCountTH;}
kkint32 foregroundCountTH
Definition: MorphOpStruct.h:58
uchar MorphOpStruct::HitForegroundCount ( kkint32  row,
kkint32  col 
) const
protected

Definition at line 152 of file MorphOpStruct.cpp.

References foregroundCountTH, KKB::MorphOp::ForegroundPixel(), KKB::MorphOp::srcGreen, KKB::MorphOp::srcHeight, KKB::MorphOp::srcWidth, structure, structureSize, and KKB::MorphOp::stSquare.

Referenced by KKB::MorphOpDilation::PerformOperation().

155 {
156  kkint32 r, c;
157  kkint32 rStart = row - structureSize;
158  kkint32 rEnd = row + structureSize;
159  kkint32 cStart = col - structureSize;
160  kkint32 cEnd = col + structureSize;
161 
162  if (rStart < 0) rStart = 0;
163  if (rEnd >= srcHeight) rEnd = srcHeight - 1;
164  if (cStart < 0) cStart = 0;
165  if (cEnd >= srcWidth) cEnd = srcWidth - 1;
166 
167  kkint32 pixelValueTotal = 0;
168  kkint32 neighborCount = 0;
169 
171  {
172  for (r = rStart; r <= rEnd; r++)
173  {
174  uchar const* rowPtr = srcGreen[r];
175 
176  for (c = cStart; c <= cEnd; c++)
177  {
178  if (ForegroundPixel (rowPtr[c]))
179  {
180  ++neighborCount;
181  pixelValueTotal += rowPtr[c];
182  }
183  }
184  }
185  }
186 
187  else
188  {
189  for (r = rStart; r <= rEnd; r++)
190  {
191  if (ForegroundPixel (srcGreen[r][col]))
192  {
193  ++neighborCount;
194  pixelValueTotal += srcGreen[r][col];
195  }
196  }
197 
198  for (c = cStart; c <= cEnd; c++)
199  {
200  if (ForegroundPixel (srcGreen[r][c]))
201  {
202  ++neighborCount;
203  pixelValueTotal += srcGreen[r][col];
204  }
205  }
206  }
207 
208  if (neighborCount < foregroundCountTH)
209  return (uchar)0;
210  else
211  return (uchar)(0.5f + (float)pixelValueTotal / (float)neighborCount);
212 } /* HitForegroundCount */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkuint16 structureSize
Definition: MorphOpStruct.h:59
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
StructureType structure
Definition: MorphOpStruct.h:56
kkint32 foregroundCountTH
Definition: MorphOpStruct.h:58
uchar *const * srcGreen
Definition: MorphOp.h:119
bool ForegroundPixel(uchar pixel) const
Definition: MorphOp.cpp:195
kkint32 MorphOpStruct::MemoryConsumedEstimated ( )

Definition at line 40 of file MorphOpStruct.cpp.

41 {
42  return sizeof (*this);
43 }
virtual OperationType KKB::MorphOpStruct::Operation ( ) const
inlinevirtual
virtual RasterPtr KKB::MorphOpStruct::PerformOperation ( RasterConstPtr  _image)
pure virtual

Member Data Documentation

kkint32 KKB::MorphOpStruct::backgroundCountTH
protected

If greater than zero; then pixel must have at least that many neighbors to be considered a fit.

Definition at line 57 of file MorphOpStruct.h.

Referenced by BackgroundCountTH(), FitBackgroundCount(), MorphOpStruct(), and KKB::MorphOpErosion::PerformOperation().

kkint32 KKB::MorphOpStruct::foregroundCountTH
protected

Definition at line 58 of file MorphOpStruct.h.

Referenced by ForegroundCountTH(), HitForegroundCount(), and MorphOpStruct().

StructureType KKB::MorphOpStruct::structure
protected

Definition at line 56 of file MorphOpStruct.h.

Referenced by Fit(), FitBackgroundCount(), HitForegroundCount(), and MorphOpStruct().

kkuint16 KKB::MorphOpStruct::structureSize
protected

Definition at line 59 of file MorphOpStruct.h.

Referenced by Fit(), FitBackgroundCount(), HitForegroundCount(), and MorphOpStruct().


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