KSquare Utilities
KKB::MorphOpErosion Class Reference

#include <MorphOpErosion.h>

+ Inheritance diagram for KKB::MorphOpErosion:

Public Member Functions

 MorphOpErosion (StructureType _structure, kkuint16 _structureSize)
 
virtual ~MorphOpErosion ()
 
kkint32 MemoryConsumedEstimated ()
 
virtual OperationType Operation () const
 
virtual RasterPtr PerformOperation (RasterConstPtr _image)
 
- Public Member Functions inherited from KKB::MorphOpStruct
 MorphOpStruct (StructureType _structure, kkuint16 _structureSize)
 
virtual ~MorphOpStruct ()
 
void BackgroundCountTH (kkint32 _backgroundCountTH)
 
void ForegroundCountTH (kkint32 _foregroundCountTH)
 
kkint32 MemoryConsumedEstimated ()
 
- 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
 

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)
 
- Protected Member Functions inherited from KKB::MorphOpStruct
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 inherited from KKB::MorphOpStruct
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
 
- Static Protected Attributes inherited from KKB::MorphOp
static kkint32 biases []
 
static StructureType maskShapes []
 

Detailed Description

Definition at line 24 of file MorphOpErosion.h.

Constructor & Destructor Documentation

MorphOpErosion::MorphOpErosion ( StructureType  _structure,
kkuint16  _structureSize 
)

Definition at line 22 of file MorphOpErosion.cpp.

References KKB::MorphOpStruct::MorphOpStruct().

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

24  :
25  MorphOpStruct (_structure, _structureSize)
26 {
27 }
MorphOpStruct(StructureType _structure, kkuint16 _structureSize)
MorphOpErosion::~MorphOpErosion ( )
virtual

Definition at line 31 of file MorphOpErosion.cpp.

32 {
33 }

Member Function Documentation

kkint32 MorphOpErosion::MemoryConsumedEstimated ( )

Definition at line 37 of file MorphOpErosion.cpp.

38 {
39  return sizeof (*this);
40 }
virtual OperationType KKB::MorphOpErosion::Operation ( ) const
inlinevirtual

Reimplemented from KKB::MorphOpStruct.

Definition at line 33 of file MorphOpErosion.h.

References KKB::MorphOp::Erosion.

RasterPtr MorphOpErosion::PerformOperation ( RasterConstPtr  _image)
virtual

Implements KKB::MorphOpStruct.

Definition at line 46 of file MorphOpErosion.cpp.

References KKB::MorphOpStruct::backgroundCountTH, KKB::Raster::BackgroundPixelValue(), KKB::MorphOpStruct::Fit(), KKB::MorphOpStruct::FitBackgroundCount(), KKB::MorphOp::ForegroundPixel(), KKB::Raster::ForegroundPixelCount(), KKB::Raster::Green(), KKB::Raster::Raster(), KKB::MorphOp::SetSrcRaster(), KKB::MorphOp::srcGreen, KKB::MorphOp::srcHeight, KKB::MorphOp::srcRaster, and KKB::MorphOp::srcWidth.

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

47 {
48  SetSrcRaster (_image);
49 
50  kkint32 r = 0;
51  kkint32 c = 0;
52 
53  kkint32 erodedForegroundPixelCount = 0;
54 
55  RasterPtr erodedRaster = new Raster (*srcRaster);
56 
57  uchar* srcRow = NULL;
58  uchar** destGreen = erodedRaster->Green ();
59  uchar* destRow = NULL;
60 
61  uchar backgroundPixelValue = srcRaster->BackgroundPixelValue ();
62 
63  for (r = 0; r < srcHeight; r++)
64  {
65  destRow = destGreen[r];
66  srcRow = srcGreen[r];
67 
68  for (c = 0; c < srcWidth; c++)
69  {
70  if (ForegroundPixel (srcRow[c]))
71  {
72  bool fit = false;
73  if (backgroundCountTH > 0)
74  fit = FitBackgroundCount (r, c);
75  else
76  fit = Fit (r, c);
77 
78  if (!fit)
79  {
80  destRow[c] = backgroundPixelValue;
81  }
82  else
83  {
84  ++erodedForegroundPixelCount;
85  }
86  }
87  } /* for (c) */
88  } /* for (r) */
89 
90  erodedRaster->ForegroundPixelCount (erodedForegroundPixelCount);
91 
92  return erodedRaster;
93 } /* PerformOperation */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
__int32 kkint32
Definition: KKBaseTypes.h:88
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
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
kkint32 ForegroundPixelCount() const
Definition: Raster.h:317
uchar backgroundPixelValue
Definition: MorphOp.h:110
bool Fit(kkint32 row, kkint32 col) const
bool FitBackgroundCount(kkint32 row, kkint32 col) const
uchar *const * srcGreen
Definition: MorphOp.h:119
RasterConstPtr srcRaster
Definition: MorphOp.h:112
bool ForegroundPixel(uchar pixel) const
Definition: MorphOp.cpp:195
uchar ** Green() const
Definition: Raster.h:327

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