KSquare Utilities
KKB::ConvexHull Class Reference

Operator that will create a Convex Hull of a supplied image. More...

#include <ConvexHull.h>

+ Inheritance diagram for KKB::ConvexHull:

Public Member Functions

 ConvexHull ()
 
virtual ~ConvexHull ()
 
kkint32 ConvexArea ()
 
void Draw (Raster &output)
 
RasterPtr Filter (const Raster &src)
 Returns a image that represents the convex-hull of the 'src' image. param[in] src Source image that convex-hull is to be found for. More...
 
RasterPtr Filter (const Raster &src, RasterPtr dest)
 
virtual OperationType Operation () const
 
virtual RasterPtr PerformOperation (RasterConstPtr _image)
 
void Store (const Raster &input)
 Build list of the upper and lower points in the image. More...
 
- 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

Operator that will create a Convex Hull of a supplied image.

Definition at line 42 of file ConvexHull.h.

Constructor & Destructor Documentation

ConvexHull::ConvexHull ( )

Definition at line 34 of file ConvexHull.cpp.

References KKB::MorphOp::MorphOp().

Referenced by KKMLL::GrayScaleImagesFVProducer::ComputeFeatureVector().

34  :
35  MorphOp (),
36  convexArea (0),
37  upperPoints (NULL),
38  lowerPoints (NULL),
39  upper (NULL),
40  lower (NULL)
41 {
42  AllocateMemory ();
43 }
ConvexHull::~ConvexHull ( )
virtual

Definition at line 46 of file ConvexHull.cpp.

47 {
48  CleanUpMemory ();
49 }

Member Function Documentation

kkint32 ConvexHull::ConvexArea ( )

Definition at line 189 of file ConvexHull.cpp.

Referenced by KKMLL::GrayScaleImagesFVProducer::ComputeFeatureVector().

190 {
191  return convexArea;
192 }
void ConvexHull::Draw ( Raster output)

Definition at line 438 of file ConvexHull.cpp.

References KKB::Point::Col(), KKB::Point::Row(), and KKB::Raster::SetPixelValue().

Referenced by Filter().

439 {
440  PointList::iterator it; // (*upper);
441  it = upper->begin ();
442 
443  PointPtr lastPoint = NULL;
444  PointPtr nextPoint = NULL;
445 
446  if (it != upper->end ())
447  {lastPoint = *it; ++it;}
448 
449  if (it != upper->end ())
450  {nextPoint = *it; ++it;}
451 
452  PointPtr firstPoint = lastPoint;
453 
454  if ((!nextPoint) && (!lastPoint))
455  return;
456 
457  if ((nextPoint != NULL) && (lastPoint == NULL))
458  {
459  output.SetPixelValue (nextPoint->Row (), nextPoint->Col (), 255);
460  return;
461  }
462 
463  while (nextPoint)
464  {
465  DrawLine (output, *lastPoint, *nextPoint, 255);
466  lastPoint = nextPoint;
467  if (it == upper->end ())
468  nextPoint = NULL;
469  else
470  {
471  nextPoint = *it;
472  ++it;
473  }
474  }
475 
476  DrawLine (output, *lastPoint, *firstPoint, 255);
477 } /* Draw */
std::vector< Point * >::iterator iterator
Definition: KKQueue.h:88
kkint32 Col() const
Definition: Point.h:40
kkint32 Row() const
Definition: Point.h:39
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
void SetPixelValue(const Point &point, const PixelValue &pixVal)
Definition: Raster.cpp:1440
RasterPtr ConvexHull::Filter ( const Raster src)

Returns a image that represents the convex-hull of the 'src' image. param[in] src Source image that convex-hull is to be found for.

Returns
A new raster that contains the convex-hull of the 'src' image; the caller will be responsible for deleting.

Definition at line 88 of file ConvexHull.cpp.

References Draw(), KKB::Raster::Height(), KKB::Raster::Raster(), KKB::MorphOp::SetSrcRaster(), Store(), and KKB::Raster::Width().

Referenced by PerformOperation().

89 {
90  SetSrcRaster (&src);
91 
92  kkint32 w = src.Width ();
93  kkint32 h = src.Height ();
94 
95  Store (src);
96 
97  RasterPtr dest = new Raster (h, w);
98 
99  if ((upperPoints->QueueSize () == 1) &&
100  (lowerPoints->QueueSize () == 1))
101  {
102  // We must have a Vertical Line
103  DrawLine (*dest, (*upperPoints)[0], (*lowerPoints)[0], 255);
104  CalcConvexArea (dest);
105  return dest;
106  }
107 
108  else if ((upperPoints->QueueSize () < 1) || (lowerPoints->QueueSize () < 1))
109  {
110  // We have Nothing
111  return dest;
112  }
113 
114  BuildUpperLink ();
115  BuildLowerLink ();
116 
117  Merge ();
118 
119  Draw (*dest);
120 
121  CalcConvexArea (dest);
122 
123  return dest;
124 } /* Filter */
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 Height() const
Definition: Raster.h:319
void Draw(Raster &output)
Definition: ConvexHull.cpp:438
kkint32 Width() const
Definition: Raster.h:324
kkint32 QueueSize() const
Definition: KKQueue.h:313
void Store(const Raster &input)
Build list of the upper and lower points in the image.
Definition: ConvexHull.cpp:738
RasterPtr ConvexHull::Filter ( const Raster src,
RasterPtr  dest 
)

Definition at line 128 of file ConvexHull.cpp.

References Draw(), KKB::Raster::Height(), KKB::Raster::ReSize(), KKB::MorphOp::SetSrcRaster(), KKB::MorphOp::srcHeight, KKB::MorphOp::srcWidth, Store(), and KKB::Raster::Width().

Referenced by KKMLL::GrayScaleImagesFVProducer::ComputeFeatureVector().

131 {
132  SetSrcRaster (&src);
133  //srcHeight = src.Height ();
134  //srcWidth = src.Width ();
135 
136 // kkint32 w = src.Width ();
137 // kkint32 h = src.Height ();
138 
139  if ((dest->Height () != srcHeight) || (dest->Width () != srcWidth))
140  dest->ReSize (srcHeight, srcWidth, false);
141 
142  Store (src);
143 
144  if ((upperPoints->QueueSize () == 1) &&
145  (lowerPoints->QueueSize () == 1))
146  {
147  // We must have a Vertical Line
148  DrawLine (*dest, (*upperPoints)[0], (*lowerPoints)[0], 255);
149  CalcConvexArea (dest);
150  return dest;
151  }
152 
153  else if ((upperPoints->QueueSize () < 1) || (lowerPoints->QueueSize () < 1))
154  {
155  // We have Nothing
156  return dest;
157  }
158 
159  BuildUpperLink ();
160  BuildLowerLink ();
161 
162  Merge ();
163 
164  Draw (*dest);
165 
166  CalcConvexArea (dest);
167 
168  return dest;
169 } /* Filter */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
kkint32 srcHeight
Definition: MorphOp.h:123
void ReSize(kkint32 _height, kkint32 _width, bool _color)
Lets you resize the raster dimensions; old image data will be lost.
Definition: Raster.cpp:898
kkint32 Height() const
Definition: Raster.h:319
kkint32 srcWidth
Definition: MorphOp.h:124
void Draw(Raster &output)
Definition: ConvexHull.cpp:438
kkint32 Width() const
Definition: Raster.h:324
kkint32 QueueSize() const
Definition: KKQueue.h:313
void Store(const Raster &input)
Build list of the upper and lower points in the image.
Definition: ConvexHull.cpp:738
virtual OperationType KKB::ConvexHull::Operation ( ) const
inlinevirtual
RasterPtr ConvexHull::PerformOperation ( RasterConstPtr  _image)
virtual

Definition at line 73 of file ConvexHull.cpp.

References Filter(), KKB::MorphOp::SetSrcRaster(), and KKB::MorphOp::srcRaster.

74 {
75  SetSrcRaster (_image);
76  AllocateMemory ();
77  RasterPtr result = Filter (*srcRaster);
78  return result;
79 } /* PerformOperation */
void SetSrcRaster(RasterConstPtr _srcRaster)
Definition: MorphOp.cpp:149
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
RasterPtr Filter(const Raster &src)
Returns a image that represents the convex-hull of the &#39;src&#39; image. param[in] src Source image that c...
Definition: ConvexHull.cpp:88
RasterConstPtr srcRaster
Definition: MorphOp.h:112
void ConvexHull::Store ( const Raster input)

Build list of the upper and lower points in the image.

for each column in the image where there is at least one foreground pixel will add one point to 'upperPoints' for the pixel with the smallest row and one point to 'lowerPoints' for the pixel with the largest row.

Parameters
[in]inputSource image that we are to generate a Convex Hull for.

for each column in the image where there is at least one foreground pixel will add one point to 'upperPoints' for the pixel with the smallest row and one point to 'lowerPoints' for the pixel with the largest row.

Parameters
[in]inputSource image that we are to generate a convex-hull for.

Definition at line 738 of file ConvexHull.cpp.

References KKB::MorphOp::ForegroundPixel(), KKB::Raster::Height(), KKB::Point::Point(), KKB::Raster::Rows(), and KKB::Raster::Width().

Referenced by Filter().

739 {
740  kkint32 w = input.Width ();
741  kkint32 h = input.Height ();
742 
743  uchar** rows = input.Rows ();
744 
745  for (kkint32 col = 0; col < w; ++col)
746  {
747  kkint32 row;
748  for (row = h - 1; row >= 0; --row)
749  {
750  if (ForegroundPixel (row, col))
751  {
752  PointPtr u = new Point (row, col);
753  upperPoints->Add (u);
754  break;
755  }
756  }
757 
758  if (row >= 0)
759  {
760  for (row = 0; row < h; row++)
761  {
762  if (ForegroundPixel (row, col))
763  {
764  PointPtr l = new Point (row, col);
765  lowerPoints->AddFirst (l);
766  break;
767  }
768  }
769  }
770  }
771 } /* Store */
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
kkint32 Height() const
Definition: Raster.h:319
virtual void Add(EntryPtr _entry)
Definition: KKQueue.h:339
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
kkint32 Width() const
Definition: Raster.h:324
virtual void AddFirst(EntryPtr _entry)
Definition: KKQueue.h:347
bool ForegroundPixel(uchar pixel) const
Definition: MorphOp.cpp:195
uchar ** Rows() const
Definition: Raster.h:321

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