KSquare Utilities
MorphOpErosion.cpp
Go to the documentation of this file.
1 /* MorphOpErosion.cpp -- Morphological operators use to perform erosion.
2  * Copyright (C) 1994-2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 
6 #include "FirstIncludes.h"
7 #include <stdlib.h>
8 #include <iostream>
9 #include <map>
10 #include <vector>
11 
12 #include "MemoryDebug.h"
13 using namespace std;
14 
15 #include "MorphOp.h"
16 #include "MorphOpErosion.h"
17 #include "Raster.h"
18 using namespace KKB;
19 
20 
21 
23  kkuint16 _structureSize
24  ):
25  MorphOpStruct (_structure, _structureSize)
26 {
27 }
28 
29 
30 
32 {
33 }
34 
35 
36 
38 {
39  return sizeof (*this);
40 }
41 
42 
43 
44 
45 
46 RasterPtr MorphOpErosion::PerformOperation (RasterConstPtr _image)
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
uchar BackgroundPixelValue() const
Definition: Raster.h:336
unsigned __int16 kkuint16
16 bit unsigned integer.
Definition: KKBaseTypes.h:86
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
MorphOpErosion(StructureType _structure, kkuint16 _structureSize)
kkint32 MemoryConsumedEstimated()
kkint32 backgroundCountTH
Definition: MorphOpStruct.h:57
kkint32 srcHeight
Definition: MorphOp.h:123
KKTHread * KKTHreadPtr
MorphOpStruct(StructureType _structure, kkuint16 _structureSize)
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
bool Fit(kkint32 row, kkint32 col) const
bool FitBackgroundCount(kkint32 row, kkint32 col) const
Raster(const Raster &_raster)
Copy Constructor.
Definition: Raster.cpp:460
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
virtual RasterPtr PerformOperation(RasterConstPtr _image)
void ForegroundPixelCount(kkint32 _foregroundPixelCount)
Definition: Raster.h:344