14 #include <Eigen/Dense> 29 profiler,
"internal_computeSpinImageDescriptors");
31 ASSERT_(options.SpinImagesOptions.radius > 1);
39 const unsigned int HIST_N_INT =
40 options.SpinImagesOptions.hist_size_intensity;
41 const unsigned int HIST_N_DIS =
42 options.SpinImagesOptions.hist_size_distance;
43 const unsigned int R = options.SpinImagesOptions.radius;
44 const int img_w =
static_cast<int>(in_img.
getWidth());
45 const int img_h =
static_cast<int>(in_img.
getHeight());
46 const bool img_color = in_img.
isColor();
50 const float k_int2idx = (HIST_N_INT - 1) / 255.0f;
51 const float k_idx2int = 1.0f / k_int2idx;
55 const float k_dis2idx = (HIST_N_DIS - 1) / static_cast<float>(
R);
56 const float k_idx2dis = 1.0f / k_dis2idx;
60 const int STD_TIMES = 2;
61 const int kernel_size_dist =
static_cast<int>(
62 ceil(k_dis2idx * STD_TIMES * options.SpinImagesOptions.std_dist));
64 const float _2var_int =
65 -1.0f / (2 *
square(options.SpinImagesOptions.std_intensity));
66 const float _2var_dist =
67 -1.0f / (2 *
square(options.SpinImagesOptions.std_dist));
73 for (
auto& in_feature : in_features)
76 in_feature.keypoint.octave = options.SpinImagesOptions.radius;
83 int px0 =
round(in_feature.keypoint.pt.x -
R);
84 int px1 =
round(in_feature.keypoint.pt.x +
R);
85 int py0 =
round(in_feature.keypoint.pt.y -
R);
86 int py1 =
round(in_feature.keypoint.pt.y +
R);
90 px1 =
min(img_w - 1, px1);
92 py1 =
min(img_h - 1, py1);
94 for (
int px = px0; px <= px1; px++)
96 for (
int py = py0; py <= py1; py++)
104 auto aux_pix_ptr = in_img.
ptr<
uint8_t>(px, py);
106 (aux_pix_ptr[0] + aux_pix_ptr[1] + aux_pix_ptr[2]) / 3;
109 const float pix_dist = hypot(
110 in_feature.keypoint.pt.x - px,
111 in_feature.keypoint.pt.y - py);
112 const int center_bin_dist = k_dis2idx * pix_dist;
125 const int bin_int_low =
126 max(0, static_cast<int>(ceil(
130 options.SpinImagesOptions.std_intensity))));
131 const int bin_int_hi =
132 min(static_cast<int>(HIST_N_INT - 1),
133 static_cast<int>(ceil(
137 options.SpinImagesOptions.std_intensity))));
141 if (center_bin_dist <
142 static_cast<int>(HIST_N_DIS))
147 const int bin_dist_low =
148 max(0, center_bin_dist - kernel_size_dist);
149 const int bin_dist_hi =
150 min(static_cast<int>(HIST_N_DIS - 1),
151 center_bin_dist + kernel_size_dist);
153 int bin_dist, bin_int;
154 float pix_dist_cur_dist =
155 pix_dist - bin_dist_low * k_idx2dis;
157 for (bin_dist = bin_dist_low; bin_dist <= bin_dist_hi;
158 bin_dist++, pix_dist_cur_dist -= k_idx2dis)
160 float pix_val_cur_val =
161 pix_val - (bin_int_low * k_idx2int);
163 for (bin_int = bin_int_low; bin_int <= bin_int_hi;
164 bin_int++, pix_val_cur_val -= k_idx2int)
167 double v = _2var_dist *
square(pix_dist_cur_dist) +
168 _2var_int *
square(pix_val_cur_val);
170 hist2d(bin_int, bin_dist) += exp(
v);
184 std::vector<float>& ptr_trg = *in_feature.descriptors.SpinImg;
185 ptr_trg.resize(HIST_N_INT * HIST_N_DIS);
187 for (
unsigned i = 0; i < HIST_N_DIS; i++)
188 for (
unsigned j = 0; j < HIST_N_INT; j++)
189 ptr_trg[idx++] = hist2d(j, i);
191 in_feature.descriptors.SpinImg_range_rows = HIST_N_DIS;
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
size_t getHeight() const override
Returns the height of the image in pixels.
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
const T & at(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries, and doing a reinterpret_cast<> of the data as the given...
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
void normalize(CONTAINER &c, Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
Classes for computer vision, detectors, features, etc.
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
const T * ptr(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel, without checking for boundaries.
A class for storing images as grayscale or RGB bitmaps.
int round(const T value)
Returns the closer integer (int) to x.