38 #ifndef PCL_2D_MORPHOLOGY_HPP_
39 #define PCL_2D_MORPHOLOGY_HPP_
43 template<
typename Po
intT>
void
46 const int height = input_->height;
47 const int width = input_->width;
48 const int kernel_height = structuring_element_->height;
49 const int kernel_width = structuring_element_->width;
54 output.
resize (width * height);
56 for (
int i = 0; i < height; i++)
58 for (
int j = 0; j < width; j++)
61 if ((*input_)(j, i).intensity == 0)
63 output (j, i).intensity = 0;
66 mismatch_flag =
false;
67 for (
int k = 0; k < kernel_height; k++)
71 for (
int l = 0; l < kernel_width; l++)
74 if ((*structuring_element_)(l, k).intensity == 0)
76 if ((i + k - kernel_height / 2) < 0 || (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 || (j + l - kernel_width / 2) >= width)
82 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity != 1)
84 output (j, i).intensity = 0;
91 output (j, i).intensity = (mismatch_flag) ? 0 : 1;
98 template <
typename Po
intT>
void
101 const int height = input_->height;
102 const int width = input_->width;
103 const int kernel_height = structuring_element_->height;
104 const int kernel_width = structuring_element_->width;
107 output.
width = width;
109 output.
resize (width * height);
111 for (
int i = 0; i < height; i++)
113 for (
int j = 0; j < width; j++)
116 for (
int k = 0; k < kernel_height; k++)
120 for (
int l = 0; l < kernel_width; l++)
123 if ((*structuring_element_)(l, k).intensity == 0)
125 if ((i + k - kernel_height / 2) < 0 || (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 || (j + l - kernel_width / 2) >= height)
131 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity == 1)
139 output (j, i).intensity = (match_flag) ? 1 : 0;
146 template <
typename Po
intT>
void
150 erosionBinary (*intermediate_output);
151 this->setInputCloud (intermediate_output);
152 dilationBinary (output);
157 template <
typename Po
intT>
void
161 dilationBinary (*intermediate_output);
162 this->setInputCloud (intermediate_output);
163 erosionBinary (output);
167 template <
typename Po
intT>
void
170 const int height = input_->height;
171 const int width = input_->width;
172 const int kernel_height = structuring_element_->height;
173 const int kernel_width = structuring_element_->width;
175 output.
resize (width * height);
176 output.
width = width;
179 for (
int i = 0; i < height; i++)
181 for (
int j = 0; j < width; j++)
184 for (
int k = 0; k < kernel_height; k++)
186 for (
int l = 0; l < kernel_width; l++)
189 if ((*structuring_element_)(l, k).intensity == 0)
191 if ((i + k - kernel_height / 2) < 0 || (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 || (j + l - kernel_width / 2) >= width)
197 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity < min || min == -1)
199 min = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity;
204 output (j, i).intensity = min;
210 template <
typename Po
intT>
void
213 const int height = input_->height;
214 const int width = input_->width;
215 const int kernel_height = structuring_element_->height;
216 const int kernel_width = structuring_element_->width;
219 output.
resize (width * height);
220 output.
width = width;
223 for (
int i = 0; i < height; i++)
225 for (
int j = 0; j < width; j++)
228 for (
int k = 0; k < kernel_height; k++)
230 for (
int l = 0; l < kernel_width; l++)
233 if ((*structuring_element_)(l, k).intensity == 0)
235 if ((i + k - kernel_height / 2) < 0 || (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 || (j + l - kernel_width / 2) >= width)
241 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity > max || max == -1)
243 max = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity;
248 output (j, i).intensity = max;
254 template <
typename Po
intT>
void
258 erosionGray (*intermediate_output);
259 this->setInputCloud (intermediate_output);
260 dilationGray (output);
264 template <
typename Po
intT>
void
268 dilationGray (*intermediate_output);
269 this->setInputCloud (intermediate_output);
270 erosionGray (output);
274 template <
typename Po
intT>
void
282 output.
width = width;
284 output.
resize (height * width);
286 for (
size_t i = 0; i < output.
size (); ++i)
288 if (input1[i].intensity == 1 && input2[i].intensity == 0)
289 output[i].intensity = 1;
291 output[i].intensity = 0;
296 template <
typename Po
intT>
void
304 output.
width = width;
306 output.
resize (height * width);
308 for (
size_t i = 0; i < output.
size (); ++i)
310 if (input1[i].intensity == 1 || input2[i].intensity == 1)
311 output[i].intensity = 1;
313 output[i].intensity = 0;
318 template <
typename Po
intT>
void
326 output.
width = width;
328 output.
resize (height * width);
330 for (
size_t i = 0; i < output.
size (); ++i)
332 if (input1[i].intensity == 1 && input2[i].intensity == 1)
333 output[i].intensity = 1;
335 output[i].intensity = 0;
340 template <
typename Po
intT>
void
344 const int dim = 2 * radius;
347 kernel.
resize (dim * dim);
349 for (
int i = 0; i < dim; i++)
351 for (
int j = 0; j < dim; j++)
353 if (((i - radius) * (i - radius) + (j - radius) * (j - radius)) < radius * radius)
354 kernel (j, i).intensity = 1;
356 kernel (j, i).intensity = 0;
362 template <
typename Po
intT>
void
367 kernel.
width = width;
368 kernel.
resize (height * width);
369 for (
size_t i = 0; i < kernel.
size (); ++i)
370 kernel[i].intensity = 1;
374 template <
typename Po
intT>
void
377 structuring_element_ = structuring_element;
380 #endif // PCL_2D_MORPHOLOGY_HPP_
void setStructuringElement(const PointCloudInPtr &structuring_element)
void dilationGray(pcl::PointCloud< PointT > &output)
Takes the max of the pixels where kernel is 1.
uint32_t width
The point cloud width (if organized as an image-structure).
void openingGray(pcl::PointCloud< PointT > &output)
Grayscale erosion followed by dilation.
void subtractionBinary(pcl::PointCloud< PointT > &output, const pcl::PointCloud< PointT > &input1, const pcl::PointCloud< PointT > &input2)
Set operation output = input1 - input2.
void structuringElementCircular(pcl::PointCloud< PointT > &kernel, const int radius)
Creates a circular structing element.
void erosionBinary(pcl::PointCloud< PointT > &output)
Binary dilation is similar to a logical disjunction of sets.
void openingBinary(pcl::PointCloud< PointT > &output)
This function performs erosion followed by dilation.
void unionBinary(pcl::PointCloud< PointT > &output, const pcl::PointCloud< PointT > &input1, const pcl::PointCloud< PointT > &input2)
Set operation .
void closingBinary(pcl::PointCloud< PointT > &output)
This function performs dilation followed by erosion.
void erosionGray(pcl::PointCloud< PointT > &output)
Takes the min of the pixels where kernel is 1.
uint32_t height
The point cloud height (if organized as an image-structure).
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void dilationBinary(pcl::PointCloud< PointT > &output)
Binary erosion is similar to a logical addition of sets.
void structuringElementRectangle(pcl::PointCloud< PointT > &kernel, const int height, const int width)
Creates a rectangular structing element of size height x width.
void closingGray(pcl::PointCloud< PointT > &output)
Grayscale dilation followed by erosion.
void resize(size_t n)
Resize the cloud.
void intersectionBinary(pcl::PointCloud< PointT > &output, const pcl::PointCloud< PointT > &input1, const pcl::PointCloud< PointT > &input2)
Set operation .