KSquare Utilities
MorphOpDilation.cpp
Go to the documentation of this file.
1 /* MorphOpDilation.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 "MorphOpStruct.h"
16 #include "MorphOpDilation.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 RasterPtr MorphOpDilation::PerformOperation (RasterConstPtr _image)
46 {
47  this->SetSrcRaster (_image);
48 
49  kkint32 r = 0;
50  kkint32 c = 0;
51 
52  kkint32 erodedForegroundPixelCount = srcRaster->ForegroundPixelCount ();
53 
54  RasterPtr resultRaster = new Raster (*srcRaster);
55 
56  uchar* srcRow = NULL;
57  uchar** destGreen = resultRaster->Green ();
58  uchar* destRow = NULL;
59 
60  kkint32 forgroundPixelCount = srcRaster->ForegroundPixelCount ();
61 
62  for (r = 0; r < srcHeight; r++)
63  {
64  destRow = destGreen[r];
65  srcRow = srcGreen[r];
66 
67  for (c = 0; c < srcWidth; c++)
68  {
69  if (BackgroundPixel (srcRow[c]))
70  {
71  uchar pixel = HitForegroundCount (r, c);
72  if (ForegroundPixel (pixel))
73  ++forgroundPixelCount;
74  destRow[c] = pixel;
75  }
76  } /* for (c) */
77  } /* for (r) */
78 
79  resultRaster->ForegroundPixelCount (forgroundPixelCount);
80 
81  return resultRaster;
82 } /* PerformOperation */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
__int32 kkint32
Definition: KKBaseTypes.h:88
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
bool BackgroundPixel(uchar pixel) const
Definition: MorphOp.cpp:171
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 MemoryConsumedEstimated()
KKTHread * KKTHreadPtr
MorphOpStruct(StructureType _structure, kkuint16 _structureSize)
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
kkint32 ForegroundPixelCount() const
Definition: Raster.h:317
MorphOpDilation(StructureType _structure, kkuint16 _structureSize)
virtual RasterPtr PerformOperation(RasterConstPtr _image)
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
uchar HitForegroundCount(kkint32 row, kkint32 col) const
void ForegroundPixelCount(kkint32 _foregroundPixelCount)
Definition: Raster.h:344