KSquare Utilities
KKB::MorphOpStretcher Class Reference

#include <MorphOpStretcher.h>

+ Inheritance diagram for KKB::MorphOpStretcher:

Classes

class  CellFactor
 

Public Member Functions

 MorphOpStretcher (float _rowFactor, float _colFactor)
 
virtual ~MorphOpStretcher ()
 
float ColFactor () const
 
kkint32 MemoryConsumedEstimated ()
 
virtual OperationType Operation () const
 
virtual RasterPtr PerformOperation (RasterConstPtr _image)
 
float RowFactor () const
 
- 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::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::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 26 of file MorphOpStretcher.h.

Constructor & Destructor Documentation

MorphOpStretcher::MorphOpStretcher ( float  _rowFactor,
float  _colFactor 
)

Definition at line 81 of file MorphOpStretcher.cpp.

References KKB::MorphOp::MorphOp().

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

83  :
84  MorphOp (),
85  rowFactor (_rowFactor),
86  colFactor (_colFactor),
87  rowFactorsCount (0),
88  rowFactors (NULL),
89  colFactorsCount (0),
90  colFactors (NULL)
91 {
92 }
MorphOpStretcher::~MorphOpStretcher ( )
virtual

Definition at line 96 of file MorphOpStretcher.cpp.

97 {
98  delete[] rowFactors; rowFactors = NULL;
99  delete[] colFactors; colFactors = NULL;
100 }

Member Function Documentation

float KKB::MorphOpStretcher::ColFactor ( ) const
inline

Definition at line 35 of file MorphOpStretcher.h.

35 {return colFactor;}
kkint32 MorphOpStretcher::MemoryConsumedEstimated ( )

Definition at line 104 of file MorphOpStretcher.cpp.

105 {
106  kkint32 result = sizeof (*this) +
107  (kkint32)(rowFactorsCount * sizeof (CellFactor) * rowFactor) +
108  (kkint32)(colFactorsCount * sizeof (CellFactor) * colFactor);
109  return result;
110 }
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual OperationType KKB::MorphOpStretcher::Operation ( ) const
inlinevirtual
RasterPtr MorphOpStretcher::PerformOperation ( RasterConstPtr  _image)
virtual

Definition at line 114 of file MorphOpStretcher.cpp.

References KKB::Raster::BackgroundPixelTH(), KKB::Raster::BackgroundPixelValue(), KKB::Raster::Blue(), KKB::Raster::Color(), KKB::MorphOpStretcher::CellFactor::destCellCount, KKB::MorphOpStretcher::CellFactor::destCellFracts, KKB::MorphOpStretcher::CellFactor::destCellIdxs, KKB::Raster::ForegroundPixelValue(), KKB::Raster::Green(), KKB::Raster::Raster(), KKB::Raster::Red(), KKB::MorphOp::SetSrcRaster(), KKB::MorphOp::srcBlue, KKB::MorphOp::srcGreen, KKB::MorphOp::srcHeight, KKB::MorphOp::srcRed, and KKB::MorphOp::srcWidth.

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

115 {
116  this->SetSrcRaster (_image);
117 
118  kkuint32 destHeight = (kkuint32)ceil (0.5f + (float)srcHeight * rowFactor);
119  kkuint32 destWidth = (kkuint32)ceil (0.5f + (float)srcWidth * colFactor);
120 
121  bool color = _image->Color ();
122 
123  UpdateFactors (srcHeight, srcWidth);
124 
125  RasterPtr result = new Raster (destHeight, destWidth, color);
126 
127  result->BackgroundPixelTH (_image->BackgroundPixelTH ());
128  result->BackgroundPixelValue (_image->BackgroundPixelValue ());
129  result->ForegroundPixelValue (_image->ForegroundPixelValue ());
130 
131  uchar** destRed = result->Red ();
132  uchar** destGreen = result->Green ();
133  uchar** destBlue = result->Blue ();
134 
135  for (kkint32 srcRow = 0; srcRow < srcHeight; ++srcRow)
136  {
137  uchar* srcRedRow = NULL;
138  uchar* srcGreenRow = srcGreen[srcRow];
139  uchar* srcBlueRow = NULL;
140  if (color)
141  {
142  srcRedRow = srcRed [srcRow];
143  srcBlueRow = srcBlue[srcRow];
144  }
145 
146  CellFactor& rowFactor = rowFactors[srcRow];
147 
148  for (kkuint32 rowFactorIdx = 0; rowFactorIdx < rowFactor.destCellCount; ++rowFactorIdx)
149  {
150  kkuint32 destRow = rowFactor.destCellIdxs [rowFactorIdx];
151  float destRowFract = rowFactor.destCellFracts[rowFactorIdx];
152 
153  for (kkint32 srcCol = 0; srcCol < srcWidth; ++srcCol)
154  {
155  uchar srcPixelRed = 0;
156  uchar srcPixelGreen = srcGreenRow[srcCol];
157  uchar srcPixelBlue = 0;
158  if (color)
159  {
160  srcPixelRed = srcRedRow [srcCol];
161  srcPixelBlue = srcBlueRow[srcCol];
162  }
163 
164  CellFactor& colFactor = colFactors[srcCol];
165 
166  for (kkuint32 colFactorIdx = 0; colFactorIdx < colFactor.destCellCount; ++colFactorIdx)
167  {
168  kkuint32 destCol = colFactor.destCellIdxs [colFactorIdx];
169  float destColFract = colFactor.destCellFracts[colFactorIdx];
170 
171  destGreen[destRow][destCol] += (uchar)Min (255.0f, srcPixelGreen * destRowFract * destColFract);
172  if (color)
173  {
174  destRed [destRow][destCol] += (uchar)Min (255.0f, srcPixelRed * destRowFract * destColFract);
175  destBlue[destRow][destCol] += (uchar)Min (255.0f, srcPixelBlue * destRowFract * destColFract);
176  }
177  }
178  }
179  }
180  }
181 
182  return result;
183 } /* PerformOperation */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
__int32 kkint32
Definition: KKBaseTypes.h:88
uchar BackgroundPixelValue() const
Definition: Raster.h:336
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
uchar ** Red() const
Definition: Raster.h:326
kkint32 srcHeight
Definition: MorphOp.h:123
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
uchar ForegroundPixelValue() const
Definition: Raster.h:337
uchar *const * srcRed
Definition: MorphOp.h:118
kkint32 srcWidth
Definition: MorphOp.h:124
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
uchar BackgroundPixelTH() const
Definition: Raster.h:335
uchar *const * srcBlue
Definition: MorphOp.h:120
uchar ** Blue() const
Definition: Raster.h:328
uchar *const * srcGreen
Definition: MorphOp.h:119
uchar ** Green() const
Definition: Raster.h:327
float KKB::MorphOpStretcher::RowFactor ( ) const
inline

Definition at line 36 of file MorphOpStretcher.h.

36 {return rowFactor;}

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