38 #ifndef PCL_2D_MORPHOLOGY_HPP_
39 #define PCL_2D_MORPHOLOGY_HPP_
43 template <
typename Po
intT>
47 const int height = input_->height;
48 const int width = input_->width;
49 const int kernel_height = structuring_element_->height;
50 const int kernel_width = structuring_element_->width;
55 output.
resize(width * height);
57 for (
int i = 0; i < height; i++) {
58 for (
int j = 0; j < width; j++) {
60 if ((*input_)(j, i).intensity == 0) {
61 output(j, i).intensity = 0;
64 mismatch_flag =
false;
65 for (
int k = 0; k < kernel_height; k++) {
68 for (
int l = 0; l < kernel_width; l++) {
70 if ((*structuring_element_)(l, k).intensity == 0)
72 if ((i + k - kernel_height / 2) < 0 ||
73 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
74 (j + l - kernel_width / 2) >= width) {
79 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
81 output(j, i).intensity = 0;
88 output(j, i).intensity = (mismatch_flag) ? 0 : 1;
95 template <
typename Po
intT>
99 const int height = input_->height;
100 const int width = input_->width;
101 const int kernel_height = structuring_element_->height;
102 const int kernel_width = structuring_element_->width;
105 output.
width = width;
107 output.
resize(width * height);
109 for (
int i = 0; i < height; i++) {
110 for (
int j = 0; j < width; j++) {
112 for (
int k = 0; k < kernel_height; k++) {
115 for (
int l = 0; l < kernel_width; l++) {
117 if ((*structuring_element_)(l, k).intensity == 0)
119 if ((i + k - kernel_height / 2) < 0 ||
120 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
121 (j + l - kernel_width / 2) >= height) {
126 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
134 output(j, i).intensity = (match_flag) ? 1 : 0;
141 template <
typename Po
intT>
146 erosionBinary(*intermediate_output);
147 this->setInputCloud(intermediate_output);
148 dilationBinary(output);
153 template <
typename Po
intT>
158 dilationBinary(*intermediate_output);
159 this->setInputCloud(intermediate_output);
160 erosionBinary(output);
164 template <
typename Po
intT>
168 const int height = input_->height;
169 const int width = input_->width;
170 const int kernel_height = structuring_element_->height;
171 const int kernel_width = structuring_element_->width;
173 output.
resize(width * height);
174 output.
width = width;
177 for (
int i = 0; i < height; i++) {
178 for (
int j = 0; j < width; j++) {
180 for (
int k = 0; k < kernel_height; k++) {
181 for (
int l = 0; l < kernel_width; l++) {
183 if ((*structuring_element_)(l, k).intensity == 0)
185 if ((i + k - kernel_height / 2) < 0 ||
186 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
187 (j + l - kernel_width / 2) >= width) {
192 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity <
195 min = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
201 output(j, i).intensity = min;
207 template <
typename Po
intT>
211 const int height = input_->height;
212 const int width = input_->width;
213 const int kernel_height = structuring_element_->height;
214 const int kernel_width = structuring_element_->width;
217 output.
resize(width * height);
218 output.
width = width;
221 for (
int i = 0; i < height; i++) {
222 for (
int j = 0; j < width; j++) {
224 for (
int k = 0; k < kernel_height; k++) {
225 for (
int l = 0; l < kernel_width; l++) {
227 if ((*structuring_element_)(l, k).intensity == 0)
229 if ((i + k - kernel_height / 2) < 0 ||
230 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
231 (j + l - kernel_width / 2) >= width) {
236 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity >
239 max = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
245 output(j, i).intensity = max;
251 template <
typename Po
intT>
256 erosionGray(*intermediate_output);
257 this->setInputCloud(intermediate_output);
258 dilationGray(output);
262 template <
typename Po
intT>
267 dilationGray(*intermediate_output);
268 this->setInputCloud(intermediate_output);
273 template <
typename Po
intT>
281 output.
width = width;
283 output.
resize(height * width);
285 for (std::size_t i = 0; i < output.
size(); ++i) {
286 if (input1[i].intensity == 1 && input2[i].intensity == 0)
287 output[i].intensity = 1;
289 output[i].intensity = 0;
294 template <
typename Po
intT>
302 output.
width = width;
304 output.
resize(height * width);
306 for (std::size_t i = 0; i < output.
size(); ++i) {
307 if (input1[i].intensity == 1 || input2[i].intensity == 1)
308 output[i].intensity = 1;
310 output[i].intensity = 0;
315 template <
typename Po
intT>
323 output.
width = width;
325 output.
resize(height * width);
327 for (std::size_t i = 0; i < output.
size(); ++i) {
328 if (input1[i].intensity == 1 && input2[i].intensity == 1)
329 output[i].intensity = 1;
331 output[i].intensity = 0;
336 template <
typename Po
intT>
341 const int dim = 2 * radius;
346 for (
int i = 0; i < dim; i++) {
347 for (
int j = 0; j < dim; j++) {
348 if (((i - radius) * (i - radius) + (j - radius) * (j - radius)) < radius * radius)
349 kernel(j, i).intensity = 1;
351 kernel(j, i).intensity = 0;
357 template <
typename Po
intT>
365 kernel.resize(height * width);
366 for (std::size_t i = 0; i <
kernel.size(); ++i)
371 template <
typename Po
intT>
374 const PointCloudInPtr& structuring_element)
376 structuring_element_ = structuring_element;
379 #endif // PCL_2D_MORPHOLOGY_HPP_