30 ASSERT_(options.SpinImagesOptions.radius > 1)
38 const unsigned int HIST_N_INT =
39 options.SpinImagesOptions.hist_size_intensity;
40 const unsigned int HIST_N_DIS =
41 options.SpinImagesOptions.hist_size_distance;
42 const unsigned int R = options.SpinImagesOptions.radius;
43 const int img_w =
static_cast<int>(in_img.
getWidth());
44 const int img_h =
static_cast<int>(in_img.
getHeight());
45 const bool img_color = in_img.
isColor();
49 const float k_int2idx = (HIST_N_INT - 1) / 255.0f;
50 const float k_idx2int = 1.0f / k_int2idx;
54 const float k_dis2idx = (HIST_N_DIS - 1) /
static_cast<float>(
R);
55 const float k_idx2dis = 1.0f / k_dis2idx;
59 const int STD_TIMES = 2;
60 const int kernel_size_dist =
static_cast<int>(
61 ceil(k_dis2idx * STD_TIMES * options.SpinImagesOptions.std_dist));
63 const float _2var_int =
64 -1.0f / (2 *
square(options.SpinImagesOptions.std_intensity));
65 const float _2var_dist =
66 -1.0f / (2 *
square(options.SpinImagesOptions.std_dist));
73 it != in_features.
end(); ++it)
76 (*it)->scale = options.SpinImagesOptions.radius;
83 int px0 =
round((*it)->x -
R);
84 int px1 =
round((*it)->x +
R);
85 int py0 =
round((*it)->y -
R);
86 int py1 =
round((*it)->y +
R);
90 px1 =
min(img_w - 1, px1);
92 py1 =
min(img_h - 1, py1);
97 for (
int px = px0; px <= px1; px++)
99 for (
int py = py0; py <= py1; py++)
108 (aux_pix_ptr[0] + aux_pix_ptr[1] + aux_pix_ptr[2]) / 3;
111 const float pix_dist = hypot((*it)->x - px, (*it)->y - py);
112 const int center_bin_dist = k_dis2idx * pix_dist;
122 const int bin_int = k_int2idx * pix_val;
124 if (center_bin_dist<
static_cast<int>(HIST_N_DIS))
126 hist2d(bin_int,center_bin_dist) +=1;
133 const int bin_int_low = max(
139 options.SpinImagesOptions.std_intensity))));
140 const int bin_int_hi =
min(
141 static_cast<int>(HIST_N_INT - 1),
147 options.SpinImagesOptions.std_intensity))));
151 if (center_bin_dist <
152 static_cast<int>(HIST_N_DIS))
157 const int bin_dist_low =
158 max(0, center_bin_dist - kernel_size_dist);
159 const int bin_dist_hi =
160 min(
static_cast<int>(HIST_N_DIS - 1),
161 center_bin_dist + kernel_size_dist);
163 int bin_dist, bin_int;
164 float pix_dist_cur_dist =
165 pix_dist - bin_dist_low * k_idx2dis;
167 for (bin_dist = bin_dist_low; bin_dist <= bin_dist_hi;
168 bin_dist++, pix_dist_cur_dist -= k_idx2dis)
170 float pix_val_cur_val =
171 pix_val - (bin_int_low * k_idx2int);
173 for (bin_int = bin_int_low; bin_int <= bin_int_hi;
174 bin_int++, pix_val_cur_val -= k_idx2int)
177 double v = _2var_dist *
square(pix_dist_cur_dist) +
178 _2var_int *
square(pix_val_cur_val);
186 hist2d.get_unsafe(bin_int, bin_dist) +=
216 std::vector<float>& ptr_trg = (*it)->descriptors.SpinImg;
217 ptr_trg.resize(HIST_N_INT * HIST_N_DIS);
219 for (
unsigned i = 0; i < HIST_N_DIS; i++)
220 for (
unsigned j = 0; j < HIST_N_INT; j++)
221 ptr_trg[idx++] =
hist2d.get_unsafe(j, i);
223 (*it)->descriptors.SpinImg_range_rows = HIST_N_DIS;
A class for storing images as grayscale or RGB bitmaps.
unsigned char * get_unsafe(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better,...
size_t getHeight() const override
Returns the height of the image in pixels.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
void drawCircle(int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1) override
Draws a circle of a given radius.
size_t getWidth() const override
Returns the width of the image in pixels.
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV).
A list of visual features, to be used as output by detectors, as input/output by trackers,...
TInternalFeatList::iterator iterator
int round(const T value)
Returns the closer integer (int) to x.
This base provides a set of functions for maths stuff.
T square(const T x)
Inline function for the square of a number.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
Classes for computer vision, detectors, features, etc.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.