40#include <pcl/recognition/quantizable_modality.h>
42#include <pcl/pcl_base.h>
43#include <pcl/point_cloud.h>
45#include <pcl/recognition/point_types.h>
46#include <pcl/filters/convolution.h>
56 template <
typename Po
intInT>
106 gradient_magnitude_threshold_ = threshold;
116 gradient_magnitude_threshold_feature_extraction_ = threshold;
125 feature_selection_method_ =
method;
141 variable_feature_nr_ =
enabled;
148 return (filtered_quantized_color_gradients_);
155 return (spreaded_filtered_quantized_color_gradients_);
162 return (color_gradients_);
174 std::vector<QuantizedMultiModFeature> & features)
const override;
184 std::vector<QuantizedMultiModFeature> & features)
const override;
243 bool variable_feature_nr_;
252 float gradient_magnitude_threshold_;
254 float gradient_magnitude_threshold_feature_extraction_;
260 std::size_t spreading_size_;
274template <
typename Po
intInT>
277 : variable_feature_nr_ (
false)
279 , feature_selection_method_ (DISTANCE_MAGNITUDE_SCORE)
280 , gradient_magnitude_threshold_ (10.0f)
281 , gradient_magnitude_threshold_feature_extraction_ (55.0f)
282 , spreading_size_ (8)
287template <
typename Po
intInT>
294template <
typename Po
intInT>
void
304 {0.25f, 0.5f, 0.25f},
305 {0.0625f, 0.25f, 0.375f, 0.25f, 0.0625f},
306 {0.03125f, 0.109375f, 0.21875f, 0.28125f, 0.21875f, 0.109375f, 0.03125f}
318 double sigmaX = sigma > 0 ? sigma : ((n-1)*0.5 - 1)*0.3 + 0.8;
322 for(
int i = 0; i < n; i++ )
324 double x = i - (n-1)*0.5;
332 for (
int i = 0; i < n; i++ )
339template <
typename Po
intInT>
358 const std::uint32_t width = input_->width;
359 const std::uint32_t height = input_->height;
381 computeMaxColorGradientsSobel (smoothed_input_);
384 quantizeColorGradients ();
387 filterQuantizedColorGradients ();
392 spreaded_filtered_quantized_color_gradients_,
397template <
typename Po
intInT>
405 spreaded_filtered_quantized_color_gradients_,
410template <
typename Po
intInT>
413 std::vector<QuantizedMultiModFeature> & features)
const
415 const std::size_t width =
mask.getWidth ();
416 const std::size_t height =
mask.getHeight ();
418 std::list<Candidate>
list1;
419 std::list<Candidate>
list2;
422 if (feature_selection_method_ == DISTANCE_MAGNITUDE_SCORE)
431 if (gradient.
magnitude > gradient_magnitude_threshold_feature_extraction_
447 if (variable_feature_nr_)
462 const float dx =
static_cast<float> (
iter1->x) -
static_cast<float> (
iter2->x);
463 const float dy =
static_cast<float> (
iter1->y) -
static_cast<float> (
iter2->y);
465 const float distance = dx*dx +
dy*
dy;
493 const float dx =
static_cast<float> (
iter2->x) -
static_cast<float> (
iter3->x);
494 const float dy =
static_cast<float> (
iter2->y) -
static_cast<float> (
iter3->y);
509 const float dx =
static_cast<float> (
iter2->x) -
static_cast<float> (
best_iter->x);
510 const float dy =
static_cast<float> (
iter2->y) -
static_cast<float> (
best_iter->y);
557 features.push_back (feature);
573 const float dx =
static_cast<float> (
iter1->x) -
static_cast<float> (
iter2->x);
574 const float dy =
static_cast<float> (
iter1->y) -
static_cast<float> (
iter2->y);
576 const float distance = dx*dx +
dy*
dy;
604 else if (feature_selection_method_ == MASK_BORDER_HIGH_GRADIENTS || feature_selection_method_ == MASK_BORDER_EQUALLY)
618 if ((feature_selection_method_ == MASK_BORDER_EQUALLY || gradient.
magnitude > gradient_magnitude_threshold_feature_extraction_)
645 features.push_back (feature);
650 std::size_t distance =
list1.
size () / nr_features + 1;
691 features.push_back (feature);
696template <
typename Po
intInT>
void
699 std::vector<QuantizedMultiModFeature> & features)
const
701 const std::size_t width =
mask.getWidth ();
702 const std::size_t height =
mask.getHeight ();
704 std::list<Candidate>
list1;
705 std::list<Candidate>
list2;
715 if (gradient.
magnitude > gradient_magnitude_threshold_feature_extraction_
740 features.push_back (feature);
745template <
typename Po
intInT>
750 const int width = cloud->width;
751 const int height = cloud->height;
753 color_gradients_.resize (width*height);
754 color_gradients_.width = width;
755 color_gradients_.height = height;
757 const float pi =
tan (1.0f) * 2;
768 const unsigned char r0 = (*cloud)[
index0].r;
769 const unsigned char g0 = (*cloud)[
index0].g;
770 const unsigned char b0 = (*cloud)[
index0].b;
772 const unsigned char r_c = (*cloud)[
index_c].r;
773 const unsigned char g_c = (*cloud)[
index_c].g;
774 const unsigned char b_c = (*cloud)[
index_c].b;
776 const unsigned char r_r = (*cloud)[
index_r].r;
777 const unsigned char g_r = (*cloud)[
index_r].g;
778 const unsigned char b_r = (*cloud)[
index_r].b;
780 const float r_dx =
static_cast<float> (
r_c) -
static_cast<float> (
r0);
781 const float g_dx =
static_cast<float> (
g_c) -
static_cast<float> (g0);
782 const float b_dx =
static_cast<float> (
b_c) -
static_cast<float> (
b0);
784 const float r_dy =
static_cast<float> (
r_r) -
static_cast<float> (
r0);
785 const float g_dy =
static_cast<float> (
g_r) -
static_cast<float> (g0);
786 const float b_dy =
static_cast<float> (
b_r) -
static_cast<float> (
b0);
832template <
typename Po
intInT>
837 const int width = cloud->width;
838 const int height = cloud->height;
840 color_gradients_.resize (width*height);
841 color_gradients_.width = width;
842 color_gradients_.height = height;
844 const float pi =
tanf (1.0f) * 2.0f;
912 gradient.
angle = std::atan2 (
static_cast<float> (
r_dy),
static_cast<float> (
r_dx)) * 180.0f / pi;
913 if (gradient.
angle < -180.0f) gradient.
angle += 360.0f;
914 if (gradient.
angle >= 180.0f) gradient.
angle -= 360.0f;
924 gradient.
angle = std::atan2 (
static_cast<float> (
g_dy),
static_cast<float> (
g_dx)) * 180.0f / pi;
925 if (gradient.
angle < -180.0f) gradient.
angle += 360.0f;
926 if (gradient.
angle >= 180.0f) gradient.
angle -= 360.0f;
936 gradient.
angle = std::atan2 (
static_cast<float> (
b_dy),
static_cast<float> (
b_dx)) * 180.0f / pi;
937 if (gradient.
angle < -180.0f) gradient.
angle += 360.0f;
938 if (gradient.
angle >= 180.0f) gradient.
angle -= 360.0f;
954template <
typename Po
intInT>
971 const std::size_t width = input_->width;
972 const std::size_t height = input_->height;
974 quantized_color_gradients_.resize (width, height);
984 if (color_gradients_ (
col_index,
row_index).magnitude < gradient_magnitude_threshold_)
991 const int quantized_value = (
static_cast<int> (angle *
angleScale)) & 7;
992 quantized_color_gradients_ (
col_index,
row_index) =
static_cast<unsigned char> (quantized_value + 1);
1017template <
typename Po
intInT>
1022 const std::size_t width = input_->width;
1023 const std::size_t height = input_->height;
1025 filtered_quantized_color_gradients_.resize (width, height);
1032 unsigned char histogram[9] = {0,0,0,0,0,0,0,0,0};
1087template <
typename Po
intInT>
1093 const std::size_t width =
mask_in.getWidth ();
1094 const std::size_t height =
mask_in.getHeight ();
Modality based on max-RGB gradients.
void filterQuantizedColorGradients()
Filters the quantized gradients.
static void erode(const pcl::MaskMap &mask_in, pcl::MaskMap &mask_out)
Erodes a mask.
void extractAllFeatures(const MaskMap &mask, std::size_t nr_features, std::size_t modalityIndex, std::vector< QuantizedMultiModFeature > &features) const override
Extracts all possible features from the modality within the specified mask.
FeatureSelectionMethod
Different methods for feature selection/extraction.
@ DISTANCE_MAGNITUDE_SCORE
@ MASK_BORDER_HIGH_GRADIENTS
void setGradientMagnitudeThresholdForFeatureExtraction(const float threshold)
Sets the threshold for the gradient magnitude which is used for feature extraction.
void computeMaxColorGradientsSobel(const typename pcl::PointCloud< pcl::RGB >::ConstPtr &cloud)
Computes the max-RGB gradients for the specified cloud using sobel.
void setVariableFeatureNr(const bool enabled)
Sets whether variable feature numbers for feature extraction is enabled.
void setSpreadingSize(const std::size_t spreading_size)
Sets the spreading size for spreading the quantized data.
void computeMaxColorGradients(const typename pcl::PointCloud< pcl::RGB >::ConstPtr &cloud)
Computes the max-RGB gradients for the specified cloud.
void setFeatureSelectionMethod(const FeatureSelectionMethod method)
Sets the feature selection method.
QuantizedMap & getQuantizedMap() override
Returns a reference to the internally computed quantized map.
virtual void processInputDataFromFiltered()
Processes the input data assuming that everything up to filtering is already done/available (so only ...
virtual void processInputData()
Processes the input data (smoothing, computing gradients, quantizing, filtering, spreading).
~ColorGradientModality()
Destructor.
void quantizeColorGradients()
Quantizes the color gradients.
ColorGradientModality()
Constructor.
void setInputCloud(const typename PointCloudIn::ConstPtr &cloud) override
Provide a pointer to the input dataset (overwrites the PCLBase::setInputCloud method)
QuantizedMap & getSpreadedQuantizedMap() override
Returns a reference to the internally computed spread quantized map.
pcl::PointCloud< pcl::GradientXY > & getMaxColorGradients()
Returns a point cloud containing the max-RGB gradients.
void extractFeatures(const MaskMap &mask, std::size_t nr_features, std::size_t modalityIndex, std::vector< QuantizedMultiModFeature > &features) const override
Extracts features from this modality within the specified mask.
void computeGaussianKernel(const std::size_t kernel_size, const float sigma, std::vector< float > &kernel_values)
Computes the Gaussian kernel used for smoothing.
void setGradientMagnitudeThreshold(const float threshold)
Sets the threshold for the gradient magnitude which is used when quantizing the data.
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
static PCL_NODISCARD MaskMap getDifferenceMask(const MaskMap &mask0, const MaskMap &mask1)
PointCloudConstPtr input_
The input point cloud dataset.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointInT > > ConstPtr
Interface for a quantizable modality.
static void spreadQuantizedMap(const QuantizedMap &input_map, QuantizedMap &output_map, std::size_t spreading_size)
Convolution is a mathematical operation on two functions f and g, producing a third function that is ...
Defines all the PCL implemented PointT point type structures.
Candidate for a feature (used in feature extraction methods).
GradientXY gradient
The gradient.
bool operator<(const Candidate &rhs) const
Operator for comparing to candidates (by magnitude of the gradient).
A point structure representing Euclidean xyz coordinates, and the intensity value.
Feature that defines a position and quantized value in a specific modality.
std::size_t modality_index
the index of the corresponding modality.
unsigned char quantized_value
the quantized value attached to the feature.
A structure representing RGB color information.