Image Component Library (ICL)
Segmentation3D.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/Segmentation3D.h **
10 ** Module : ICLGeom **
11 ** Authors: Andre Ueckermann **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLGeom/GeomDefs.h>
35 #include <ICLCore/Img.h>
37 #include <ICLCV/RegionDetector.h>
38 
39 #ifdef ICL_HAVE_OPENCL
40 #include <ICLUtils/CLProgram.h>
41 #include <ICLUtils/CLBuffer.h>
42 #include <ICLUtils/CLKernel.h>
43 #endif
44 
45 namespace icl{
46  namespace geom{
50 
51  public:
53 
56 
58  ~Segmentation3D();
59 
61 
65  core::Img8u segmentation(core::DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg);
66 
68 
72  core::Img8u segmentationBlobs(core::DataSegment<float,4> xyz, const core::Img8u &edgeImg, const core::Img32f &depthImg);
73 
75 
76  void setUseCL(bool use);
77 
79 
80  void setUseROI(bool use);
81 
83 
87  void setROI(float xMin, float xMax, float yMin, float yMax);
88 
90 
91  void setMinClusterSize(unsigned int size);
92 
94 
95  void setUseFastGrowing(bool use);
96 
98 
99  void setAssignmentRadius(int radius);
100 
102 
103  void setAssignmentMaxDistance(float maxDistance);
104 
106 
107  void setRANSACeuclDistance(int distance);
108 
110 
111  void setRANSACpasses(int passes);
112 
114 
115  void setRANSACtolerance(int tolerance);
116 
118 
119  void setRANSACsubset(int subset);
120 
122 
123  void setBLOBSeuclDistance(int distance);
124 
126 
127  bool isCLReady();
128 
130 
131  bool isCLActive();
132 
134 
135  core::Img8u getSegmentColorImage();
136 
138 
139  std::vector<std::vector<int> > getCluster();
140 
142 
143  std::vector<std::vector<int> > getBlobs();
144 
146 
147  const int* getAssignment();
148 
150 
151  math::DynMatrix<bool> getNeigboursMatrix();
152 
154 
155  math::DynMatrix<float> getProbabilityMatrix();
156 
158 
159  void setXYZH(core::DataSegment<float,4> xyz);
160 
162 
163  void setEdgeImage(const core::Img8u &edgeImage);
164 
166 
167  void setDepthImage(const core::Img32f &depth);
168 
170  void clearData();
171 
173  void regionGrow();
174 
176  void calculatePointAssignmentAndAdjacency();
177 
179  void calculateCutfreeMatrix();
180 
182  void greedyComposition();
183 
185  void calculateRemainingPoints();
186 
188  void blobSegmentation();
189 
191  void colorPointcloud();
192 
193  private:
194 
195  int w,h,dim;
197 
198  float xMinROI, xMaxROI, yMinROI, yMaxROI;
199  bool useROI;
200 
201  bool* elements;
206 
210 
212 
213  std::vector<std::vector<int> > cluster;
214  std::vector<std::vector<int> > blobs;
215  unsigned int minClusterSize;
224 
228 
230 
231  bool clReady;
232  bool useCL;
233 
234  void checkNeighbourGrayThreshold(int x, int y, int zuw, int threshold, std::vector<int> *data);
235 
236  void checkNeighbourDistanceRemaining(int x, int y, int zuw, std::vector<int> *data);
237 
238  void regionGrowBlobs();
239 
240  void checkNeighbourDistance(int x, int y, int zuw, std::vector<int> *data);
241 
242  bool checkNotExist(int zw, std::vector<int> &nb);
243 
244  float dist3(const Vec &a, const Vec &b);
245 
246  #ifdef ICL_HAVE_OPENCL
247  //OpenCL data
248  unsigned char* segmentColorImageRArray;
249  unsigned char* segmentColorImageGArray;
250  unsigned char* segmentColorImageBArray;
251 
252  //OpenCL
258 
259  //OpenCL buffer
270  #endif
271  };
272  } // namespace geom
273 }
math::DynMatrix< float > probabilities
Definition: Segmentation3D.h:227
std::vector< std::vector< int > > cluster
Definition: Segmentation3D.h:213
int RANSACpasses
Definition: Segmentation3D.h:220
undocument this line if you encounter any issues!
Definition: Any.h:37
int w
Definition: Segmentation3D.h:195
core::Img8u normalEdgeImage
Definition: Segmentation3D.h:208
unsigned char * segmentColorImageRArray
Definition: Segmentation3D.h:248
int BLOBSeuclDistance
Definition: Segmentation3D.h:223
utils::CLBuffer segmentColorImageRBuffer
Definition: Segmentation3D.h:260
math::DynMatrix< bool > neighbours
Definition: Segmentation3D.h:225
#define ICLGeom_API
Definition: CompatMacros.h:179
math::DynMatrix< bool > cutfree
Definition: Segmentation3D.h:226
Wrapper for an OpenCL Kernel.
Definition: CLKernel.h:72
utils::CLBuffer elementsBlobsBuffer
Definition: Segmentation3D.h:269
utils::CLKernel kernelSegmentColoring
Definition: Segmentation3D.h:254
utils::CLBuffer segmentColorImageGBuffer
Definition: Segmentation3D.h:261
utils::CLBuffer assignmentBuffer
Definition: Segmentation3D.h:263
utils::CLKernel kernelCheckRANSAC
Definition: Segmentation3D.h:256
bool clReady
Definition: Segmentation3D.h:231
core::DataSegment< float, 4 > xyzData
Definition: Segmentation3D.h:207
unsigned int minClusterSize
Definition: Segmentation3D.h:215
utils::CLBuffer neighboursBuffer
Definition: Segmentation3D.h:264
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
utils::CLProgram program
Definition: Segmentation3D.h:253
int assignmentRadius
Definition: Segmentation3D.h:217
bool useFastGrowing
Definition: Segmentation3D.h:216
Wrapper for an OpenCL Buffer.
Definition: CLBuffer.h:52
utils::CLBuffer xyzBuffer
Definition: Segmentation3D.h:267
Size class of the ICL.
Definition: Size.h:61
std::vector< std::vector< int > > blobs
Definition: Segmentation3D.h:214
int * assignmentBlobs
Definition: Segmentation3D.h:205
utils::CLKernel kernelPointAssignment
Definition: Segmentation3D.h:255
utils::CLBuffer assignmentBlobsBuffer
Definition: Segmentation3D.h:268
utils::CLKernel kernelAssignRANSAC
Definition: Segmentation3D.h:257
int RANSACeuclDistance
Definition: Segmentation3D.h:219
Complex utility class for detection of connected image components.
Definition: RegionDetector.h:179
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
utils::CLBuffer assignmentOutBuffer
Definition: Segmentation3D.h:266
float yMinROI
Definition: Segmentation3D.h:198
bool * elements
Definition: Segmentation3D.h:201
utils::Size s
Definition: Segmentation3D.h:196
core::Img8u segmentColorImage
Definition: Segmentation3D.h:211
int * assignmentRemaining
Definition: Segmentation3D.h:203
int RANSACsubset
Definition: Segmentation3D.h:222
Definition: Segmentation3D.h:49
core::Img32f depthImage
Definition: Segmentation3D.h:209
bool * elementsBlobs
Definition: Segmentation3D.h:204
utils::CLBuffer segmentColorImageBBuffer
Definition: Segmentation3D.h:262
utils::CLBuffer elementsBuffer
Definition: Segmentation3D.h:265
unsigned char * segmentColorImageGArray
Definition: Segmentation3D.h:249
unsigned char * segmentColorImageBArray
Definition: Segmentation3D.h:250
bool useCL
Definition: Segmentation3D.h:232
bool useROI
Definition: Segmentation3D.h:199
int * assignment
Definition: Segmentation3D.h:202
Main class for OpenCL based accelleration.
Definition: CLProgram.h:259
cv::RegionDetector * region
Definition: Segmentation3D.h:229
float assignmentMaxDistance
Definition: Segmentation3D.h:218
float dist3(const Vec4 &a, const Vec4 &b)
3d euclidian distance
Definition: HomogeneousMath.h:179
int RANSACtolerance
Definition: Segmentation3D.h:221