31 ASSERT_(options.SpinImagesOptions.radius>1)
37 const unsigned int HIST_N_INT = options.SpinImagesOptions.hist_size_intensity;
38 const unsigned int HIST_N_DIS = options.SpinImagesOptions.hist_size_distance;
39 const unsigned int R = options.SpinImagesOptions.radius;
40 const int img_w =
static_cast<int>( in_img.
getWidth() );
41 const int img_h =
static_cast<int>( in_img.
getHeight() );
42 const bool img_color = in_img.
isColor();
45 const float k_int2idx = (HIST_N_INT-1) / 255.0f;
46 const float k_idx2int = 1.0f/k_int2idx;
49 const float k_dis2idx = (HIST_N_DIS-1) / static_cast<float>(
R);
50 const float k_idx2dis = 1.0f/k_dis2idx;
54 const int STD_TIMES = 2;
55 const int kernel_size_dist =
static_cast<int>( ceil(k_dis2idx * STD_TIMES * options.SpinImagesOptions.std_dist) );
57 const float _2var_int = -1.0f/(2*
square( options.SpinImagesOptions.std_intensity ));
58 const float _2var_dist = -1.0f/(2*
square( options.SpinImagesOptions.std_dist ));
68 (*it)->scale = options.SpinImagesOptions.radius;
74 int px0 =
round( (*it)->x -
R );
75 int px1 =
round( (*it)->x +
R );
76 int py0 =
round( (*it)->y -
R );
77 int py1 =
round( (*it)->y +
R );
88 for (
int px=px0;px<=px1;px++)
90 for (
int py=py0;py<=py1;py++)
98 pix_val = (aux_pix_ptr[0] + aux_pix_ptr[1] + aux_pix_ptr[2]) / 3;
101 const float pix_dist = hypot( (*it)->x - px, (*it)->y - py );
102 const int center_bin_dist = k_dis2idx * pix_dist;
110 const int bin_int = k_int2idx * pix_val;
112 if (center_bin_dist<static_cast<int>(HIST_N_DIS))
114 hist2d(bin_int,center_bin_dist) +=1;
119 const int bin_int_low = max(0, static_cast<int>(ceil(k_int2idx * ( pix_val - STD_TIMES * options.SpinImagesOptions.std_intensity ))) );
120 const int bin_int_hi =
min(static_cast<int>(HIST_N_INT-1), static_cast<int>(ceil(k_int2idx * ( pix_val + STD_TIMES * options.SpinImagesOptions.std_intensity ))));
124 if (center_bin_dist<static_cast<int>(HIST_N_DIS))
126 const int bin_dist_low = max(0, center_bin_dist-kernel_size_dist);
127 const int bin_dist_hi =
min(static_cast<int>(HIST_N_DIS-1), center_bin_dist+kernel_size_dist);
129 int bin_dist, bin_int;
130 float pix_dist_cur_dist = pix_dist - bin_dist_low*k_idx2dis;
132 for (bin_dist = bin_dist_low;bin_dist<=bin_dist_hi;bin_dist++, pix_dist_cur_dist-=k_idx2dis)
134 float pix_val_cur_val = pix_val-(bin_int_low*k_idx2int);
136 for (bin_int=bin_int_low;bin_int<=bin_int_hi;bin_int++, pix_val_cur_val-=k_idx2int)
139 double v = _2var_dist *
square(pix_dist_cur_dist) + _2var_int *
square(pix_val_cur_val);
143 hist2d.get_unsafe(bin_int,bin_dist) += exp(
v);
172 std::vector<float> &ptr_trg = (*it)->descriptors.SpinImg;
173 ptr_trg.resize( HIST_N_INT * HIST_N_DIS );
175 for (
unsigned i=0;i<HIST_N_DIS;i++)
176 for (
unsigned j=0;j<HIST_N_INT;j++)
177 ptr_trg[idx++] =
hist2d.get_unsafe(j,i);
179 (*it)->descriptors.SpinImg_range_rows = HIST_N_DIS;
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
A class for storing images as grayscale or RGB bitmaps.
void drawCircle(int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1) MRPT_OVERRIDE
Draws a circle of a given radius.
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
int round(const T value)
Returns the closer integer (int) to x.
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)...
TInternalFeatList::iterator iterator
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
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, which checks the coordinates.
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels.
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.