40 #include <pcl/2d/morphology.h>
45 template <
typename Po
intT>
49 const int height = input_->height;
50 const int width = input_->width;
51 const int kernel_height = structuring_element_->height;
52 const int kernel_width = structuring_element_->width;
57 output.
resize(width * height);
59 for (
int i = 0; i < height; i++) {
60 for (
int j = 0; j < width; j++) {
62 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++) {
70 for (
int l = 0; l < kernel_width; l++) {
72 if ((*structuring_element_)(l, k).intensity == 0)
74 if ((i + k - kernel_height / 2) < 0 ||
75 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
76 (j + l - kernel_width / 2) >= width) {
81 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
83 output(j, i).intensity = 0;
90 output(j, i).intensity = (mismatch_flag) ? 0 : 1;
96 template <
typename Po
intT>
100 const int height = input_->height;
101 const int width = input_->width;
102 const int kernel_height = structuring_element_->height;
103 const int kernel_width = structuring_element_->width;
106 output.
width = width;
108 output.
resize(width * height);
110 for (
int i = 0; i < height; i++) {
111 for (
int j = 0; j < width; j++) {
113 for (
int k = 0; k < kernel_height; k++) {
116 for (
int l = 0; l < kernel_width; l++) {
118 if ((*structuring_element_)(l, k).intensity == 0)
120 if ((i + k - kernel_height / 2) < 0 ||
121 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
122 (j + l - kernel_width / 2) >= height) {
127 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
135 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);
152 template <
typename Po
intT>
157 dilationBinary(*intermediate_output);
158 this->setInputCloud(intermediate_output);
159 erosionBinary(output);
162 template <
typename Po
intT>
166 const int height = input_->height;
167 const int width = input_->width;
168 const int kernel_height = structuring_element_->height;
169 const int kernel_width = structuring_element_->width;
171 output.
resize(width * height);
172 output.
width = width;
175 for (
int i = 0; i < height; i++) {
176 for (
int j = 0; j < width; j++) {
178 for (
int k = 0; k < kernel_height; k++) {
179 for (
int l = 0; l < kernel_width; l++) {
181 if ((*structuring_element_)(l, k).intensity == 0)
183 if ((i + k - kernel_height / 2) < 0 ||
184 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
185 (j + l - kernel_width / 2) >= width) {
190 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity <
193 min = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
199 output(j, i).intensity = min;
204 template <
typename Po
intT>
208 const int height = input_->height;
209 const int width = input_->width;
210 const int kernel_height = structuring_element_->height;
211 const int kernel_width = structuring_element_->width;
214 output.
resize(width * height);
215 output.
width = width;
218 for (
int i = 0; i < height; i++) {
219 for (
int j = 0; j < width; j++) {
221 for (
int k = 0; k < kernel_height; k++) {
222 for (
int l = 0; l < kernel_width; l++) {
224 if ((*structuring_element_)(l, k).intensity == 0)
226 if ((i + k - kernel_height / 2) < 0 ||
227 (i + k - kernel_height / 2) >= height || (j + l - kernel_width / 2) < 0 ||
228 (j + l - kernel_width / 2) >= width) {
233 if ((*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2).intensity >
236 max = (*input_)(j + l - kernel_width / 2, i + k - kernel_height / 2)
242 output(j, i).intensity = max;
247 template <
typename Po
intT>
252 erosionGray(*intermediate_output);
253 this->setInputCloud(intermediate_output);
254 dilationGray(output);
257 template <
typename Po
intT>
262 dilationGray(*intermediate_output);
263 this->setInputCloud(intermediate_output);
267 template <
typename Po
intT>
275 output.
width = width;
277 output.
resize(height * width);
279 for (std::size_t i = 0; i < output.
size(); ++i) {
280 if (input1[i].intensity == 1 && input2[i].intensity == 0)
281 output[i].intensity = 1;
283 output[i].intensity = 0;
287 template <
typename Po
intT>
295 output.
width = width;
297 output.
resize(height * width);
299 for (std::size_t i = 0; i < output.
size(); ++i) {
300 if (input1[i].intensity == 1 || input2[i].intensity == 1)
301 output[i].intensity = 1;
303 output[i].intensity = 0;
307 template <
typename Po
intT>
315 output.
width = width;
317 output.
resize(height * width);
319 for (std::size_t i = 0; i < output.
size(); ++i) {
320 if (input1[i].intensity == 1 && input2[i].intensity == 1)
321 output[i].intensity = 1;
323 output[i].intensity = 0;
327 template <
typename Po
intT>
332 const int dim = 2 * radius;
337 for (
int i = 0; i < dim; i++) {
338 for (
int j = 0; j < dim; j++) {
339 if (((i - radius) * (i - radius) + (j - radius) * (j - radius)) < radius * radius)
340 kernel(j, i).intensity = 1;
342 kernel(j, i).intensity = 0;
347 template <
typename Po
intT>
355 kernel.resize(height * width);
356 for (std::size_t i = 0; i <
kernel.size(); ++i)
360 template <
typename Po
intT>
364 structuring_element_ = structuring_element;