KSquare Utilities
MorphOp.cpp
Go to the documentation of this file.
1 /* MorphOp.cpp -- Base class to be used by all Morphological operators..
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 "Raster.h"
16 
17 #include "MorphOp.h"
18 using namespace KKB;
19 
20 
21 
22 
23 
24 kkint32 MorphOp::biases[] = {1, // CROSS3
25  2, // CROSS5
26  1, // SQUARE3
27  2, // SQUARE5
28  3, // SQUARE7
29  4, // SQUARE9
30  5 // SQUARE11
31  };
32 
33 
34 StructureType MorphOp::maskShapes[] = {StructureType::stCross, // CROSS3
35  StructureType::stCross, // CROSS5
36  StructureType::stSquare, // SQUARE3
37  StructureType::stSquare, // SQUARE5
38  StructureType::stSquare, // SQUARE7
39  StructureType::stSquare, // SQUARE9
40  StructureType::stSquare // SQUARE11
41  };
42 
43 
45 {
46  if (mt < MaskTypes::CROSS3)
47  mt = MaskTypes::CROSS3;
48 
49  else if (mt > MaskTypes::SQUARE9)
50  mt = MaskTypes::SQUARE9;
51 
52  return biases[(int)mt];
53 }
54 
55 
56 
57 StructureType MorphOp::MaskShapes (MaskTypes mt)
58 {
59  if (mt < MaskTypes::CROSS3)
60  mt = MaskTypes::CROSS3;
61 
62  else if (mt > MaskTypes::SQUARE9)
63  mt = MaskTypes::SQUARE9;
64 
65  return maskShapes[(int)mt];
66 }
67 
68 
69 
70 
71 
72 
74  backgroundPixelTH (31),
76  srcRaster (NULL),
77  srcRedArea (NULL),
78  srcGreenArea (NULL),
79  srcBlueArea (NULL),
80  srcRed (NULL),
81  srcGreen (NULL),
82  srcBlue (NULL),
83  srcColor (false),
84  srcHeight (0),
85  srcWidth (0)
86 {
87 }
88 
89 
90 
92 {
93 }
94 
95 
96 
98 {
99  if (_operation == OperationType::Stretcher)
100  return "Stretcher";
101 
102  else if (_operation == OperationType::BmiFiltering)
103  return "BmiFiltering";
104 
105  else if (_operation == OperationType::ConvexHull)
106  return "ConvexHull";
107 
108  else if (_operation == OperationType::Dilation)
109  return "Dilation";
110 
111  else if (_operation == OperationType::Erosion)
112  return "Erosion";
113 
114  else if (_operation == OperationType::MaskExclude)
115  return "MaskExclude";
116 
117  else
118  return "NULL";
119 }
120 
121 
122 
124 {
125  if (_operationStr.EqualIgnoreCase ("Stretcher"))
127 
128  else if (_operationStr.EqualIgnoreCase ("Binarize"))
130 
131  else if (_operationStr.EqualIgnoreCase ("BmiFiltering"))
133 
134  else if (_operationStr.EqualIgnoreCase ("ConvexHull"))
136 
137  else if (_operationStr.EqualIgnoreCase ("Erosion"))
138  return OperationType::Erosion;
139 
140  else if (_operationStr.EqualIgnoreCase ("MaskExclude"))
142 
143  else
144  return OperationType::Null;
145 }
146 
147 
148 
149 void MorphOp::SetSrcRaster (RasterConstPtr _srcRaster)
150 {
151  srcRaster = _srcRaster;
152 
156 
159 
163 
167 } /* SetSrcRaster */
168 
169 
170 
171 bool MorphOp::BackgroundPixel (uchar pixel) const
172 {
173  return (pixel <= backgroundPixelTH);
174 } /* BackgroundPixel */
175 
176 
177 
179  kkint32 col
180  ) const
181 {
182  if ((row < 0) ||
183  (row >= srcHeight) ||
184  (col < 0) ||
185  (col >= srcWidth) ||
186  (srcGreen == NULL)
187  )
188  return false;
189 
190  return (srcGreen[row][col] <= backgroundPixelTH);
191 } /* BackgroundPixel */
192 
193 
194 
195 bool MorphOp::ForegroundPixel (uchar pixel) const
196 {
197  return (pixel > backgroundPixelTH);
198 } /* ForegroundPixel */
199 
200 
201 
203  kkint32 col
204  ) const
205 {
206  if ((row < 0) ||
207  (row >= srcHeight) ||
208  (col < 0) ||
209  (col >= srcWidth) ||
210  (srcGreen == NULL)
211  )
212  return false;
213 
214  return (srcGreen[row][col] > backgroundPixelTH);
215 } /* ForegroundPixel */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
static kkint32 biases[]
Definition: MorphOp.h:126
bool EqualIgnoreCase(const char *s2) const
Definition: KKStr.cpp:1257
__int32 kkint32
Definition: KKBaseTypes.h:88
uchar BackgroundPixelValue() const
Definition: Raster.h:336
OperationType OperationTypeFromStr(const KKB::KKStr &_operationStr)
Definition: MorphOp.cpp:123
bool BackgroundPixel(uchar pixel) const
Definition: MorphOp.cpp:171
static StructureType MaskShapes(MaskTypes mt)
Definition: MorphOp.cpp:57
static kkint32 Biases(MaskTypes mt)
Definition: MorphOp.cpp:44
bool srcColor
Definition: MorphOp.h:122
bool Color() const
Definition: Raster.h:310
uchar ** Red() const
Definition: Raster.h:326
kkint32 srcHeight
Definition: MorphOp.h:123
kkint32 Height() const
Definition: Raster.h:319
KKTHread * KKTHreadPtr
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
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
uchar BackgroundPixelTH() const
Definition: Raster.h:335
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
uchar * RedArea() const
Definition: Raster.h:329
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
uchar * GreenArea() const
Definition: Raster.h:330
uchar * BlueArea() const
Definition: Raster.h:331
kkint32 Width() const
Definition: Raster.h:324
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 ** Blue() const
Definition: Raster.h:328
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
uchar ** Green() const
Definition: Raster.h:327