KSquare Utilities
Blob.h
Go to the documentation of this file.
1 /* Blob.h -- Works with Raster class to track individual connected component in Raster.
2  * Copyright (C) 1994-2011 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 
6 #ifndef _BLOB_
7 #define _BLOB_
8 /**
9  *@class KKB::Blob
10  *@brief Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id.
11  *
12  *@details It is used by the Raster object while performing a connected component analysis. For each distinct
13  * blob located an instance of this class will be created. Its location in the raster and its unique
14  * blob ID will be stored here. These blobs will later be able to be extracted from the image by
15  * referencing this blob.
16  *
17  * The "id" field in this blob will be stored in a array in the associated Raster object. This allows
18  * the Raster object to identify the specific pixels that belong to this Blob. Using the fields "colLeft"
19  * "colRight", "rowBot", and "rowTop" the Raster object will be able to quickly locate the associated
20  * blob.
21  *
22  *@see KKB::Raster
23  *@see KKB::Raster::ExtractABlob
24  *@see KKB::Raster::ExtractABlobTightly
25  */
26 
27 #include "KKQueue.h"
28 #include "Point.h"
29 
30 namespace KKB
31 {
32  class Blob
33  {
34  friend class BlobList;
35 
36  public:
37  Blob (kkint32 _id);
38 
39  ~Blob ();
40 
41  void InitialzieAsNew (kkint32 _id);
42 
43 
44  kkint32 Id () {return id;} /**< @brief The unique ID assigned to this blob. @see BlobList::nextBlobId */
45 
46  kkint32 ColLeft () {return colLeft;} /**< @brief Left most column in the raster object that this blob occupies. */
47  kkint32 ColRight () {return colRight;} /**< @brief Right most column in the raster object that this blob occupies. */
48 
49  kkint32 Height () {return (1 + abs (rowBot - rowTop));} /**< @brief Number of rows that the blob occupies. */
50 
51  kkint32 RowBot () {return rowBot;} /**< @brief Bottom row in the raster object that this blob occupies. */
52  kkint32 RowTop () {return rowTop;} /**< @brief Top row in the raster object that this blob occupies. */
53 
54  kkint32 Width () {return (1 + abs (colLeft - colRight));} /**< @brief Number of columns that this blob occupies. */
55 
56  kkint32 PixelCount () {return pixelCount;} /**< @brief Number of pixels that are part of this blob. */
57 
58  Point TopLeft () const {return Point (rowTop, colLeft);} /**< @brief Returns a point to the Top Left corner of the blob. */
59  Point BotRight () const {return Point (rowBot, colRight);} /**< @brief Returns a point to the Bottom Right corner of the blob. */
60 
67  }; /* Blob */
68 
69 
70  typedef Blob* BlobPtr;
71 
72 
73  /**
74  *@class BlobList
75  *@brief Maintains a list of blobs.
76  */
77  class BlobList: public std::map<kkint32,BlobPtr>
78  {
79  public:
80  BlobList (bool _owner);
81 
82  ~BlobList ();
83 
84 
85  void DeleteEntry (BlobPtr b);
86 
87  BlobPtr LookUpByBlobId (kkint32 blobId); /**< @brief Will return pointer to blob with 'blobId'; if not found will return NULL. */
88 
89  BlobPtr LocateLargestBlob (); /**< @brief Will return Blob with largest pixel count. */
90 
91  /**
92  *@brief Locates the blob that covers the greatest part of the raster; that is the one who has the
93  * largest (Height x Width)
94  */
96 
97 
98 
99  /**
100  *@brief Used by the Connected component analysis to merge two blobs together.
101  *@details When the connected component discovers that two separate blobs are actually connected
102  * if will call this method to merge them together into a single blob.
103  */
104  void MergeBlobIds (BlobPtr blob,
105  kkint32 blobId,
106  kkint32** blobIds
107  );
108 
110  kkint32 blob2Id,
111  kkint32** blobIds
112  );
113 
114  BlobPtr NewBlob (kkuint32 rowTop,
115  kkuint32 colLeft
116  );
117 
118  void PushOnBack (BlobPtr blob);
119 
120  void PushOnFront (BlobPtr blob);
121 
122  private:
123  typedef std::pair<kkint32,BlobPtr> BlobIndexPair;
124 
125  std::vector<BlobPtr> availableBlobs;
126  kkint32 nextBlobId;
127  };
128 
129 
131 
132 } /* namespace KKB; */
133 
134 #endif
Point BotRight() const
Returns a point to the Bottom Right corner of the blob.
Definition: Blob.h:59
Blob(kkint32 _id)
Definition: Blob.cpp:22
BlobPtr LocateMostComplete()
Locates the blob that covers the greatest part of the raster; that is the one who has the largest (He...
Definition: Blob.cpp:253
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 Width()
Number of columns that this blob occupies.
Definition: Blob.h:54
kkint32 colLeft
Definition: Blob.h:61
kkint32 rowBot
Definition: Blob.h:65
Blob * BlobPtr
Definition: Blob.h:70
void DeleteEntry(BlobPtr b)
BlobList * BlobListPtr
Definition: Blob.h:130
BlobPtr NewBlob(kkuint32 rowTop, kkuint32 colLeft)
Definition: Blob.cpp:93
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
kkint32 Height()
Number of rows that the blob occupies.
Definition: Blob.h:49
kkint32 ColLeft()
Left most column in the raster object that this blob occupies.
Definition: Blob.h:46
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
KKTHread * KKTHreadPtr
~Blob()
Definition: Blob.cpp:35
kkint32 rowTop
Definition: Blob.h:66
void PushOnBack(BlobPtr blob)
Definition: Blob.cpp:280
void MergeBlobIds(BlobPtr blob, kkint32 blobId, kkint32 **blobIds)
Used by the Connected component analysis to merge two blobs together.
Definition: Blob.cpp:122
Point(kkint32 _row, kkint32 _col)
Definition: Point.cpp:43
kkint32 RowBot()
Bottom row in the raster object that this blob occupies.
Definition: Blob.h:51
friend std::ostream & operator<<(std::ostream &os, const Matrix &matrix)
Maintains a list of blobs.
Definition: Blob.h:77
Point TopLeft() const
Returns a point to the Top Left corner of the blob.
Definition: Blob.h:58
BlobPtr LocateLargestBlob()
Will return Blob with largest pixel count.
Definition: Blob.cpp:230
kkint32 pixelCount
Definition: Blob.h:64
kkint32 PixelCount()
Number of pixels that are part of this blob.
Definition: Blob.h:56
kkint32 RowTop()
Top row in the raster object that this blob occupies.
Definition: Blob.h:52
kkint32 ColRight()
Right most column in the raster object that this blob occupies.
Definition: Blob.h:47
BlobPtr LookUpByBlobId(kkint32 blobId)
Will return pointer to blob with &#39;blobId&#39;; if not found will return NULL.
Definition: Blob.cpp:53
kkint32 Id()
The unique ID assigned to this blob.
Definition: Blob.h:44
kkint32 colRight
Definition: Blob.h:62
void InitialzieAsNew(kkint32 _id)
Definition: Blob.cpp:41
BlobList(bool _owner)
Definition: Blob.cpp:64
BlobPtr MergeIntoSingleBlob(BlobPtr blob1, kkint32 blob2Id, kkint32 **blobIds)
Definition: Blob.cpp:163
void PushOnFront(BlobPtr blob)
Definition: Blob.cpp:287
kkint32 id
Definition: Blob.h:63