41 void hog_orientation_compute(
const SimpleTensor<T> &mag,
const SimpleTensor<T> &
phase, std::vector<T> &bins,
const HOGInfo &hog_info)
43 const Size2D &cell_size = hog_info.cell_size();
44 const size_t num_bins = hog_info.num_bins();
46 float phase_scale = (
PhaseType::SIGNED == hog_info.phase_type() ? num_bins / 360.0f : num_bins / 180.0f);
47 phase_scale *= (
PhaseType::SIGNED == hog_info.phase_type() ? 360.0f / 255.0f : 1.0f);
50 for(
size_t yc = 0; yc < cell_size.height; ++yc)
52 for(
size_t xc = 0; xc < cell_size.width; xc++)
54 const float mag_value = mag[(row_idx + xc)];
55 const float phase_value = phase[(row_idx + xc)] * phase_scale + 0.5f;
56 const float w1 = phase_value - floor(phase_value);
60 const auto hidx =
static_cast<unsigned int>(phase_value) % num_bins;
63 bins[hidx] += mag_value * (1.0f - w1);
64 bins[(hidx + 1) % num_bins] += mag_value * w1;
67 row_idx += cell_size.width;
72 void hog_block_normalization_compute(SimpleTensor<T> &block, SimpleTensor<T> &desc,
const HOGInfo &hog_info,
size_t block_idx)
74 const int num_bins_per_block = desc.num_channels();
75 const HOGNormType norm_type = hog_info.normalization_type();
76 const Coordinates
id =
index2coord(desc.shape(), block_idx);
81 for(
int i = 0; i < num_bins_per_block; ++i)
83 const float val = block[i];
88 float scale = 1.0f / (std::sqrt(sum) + num_bins_per_block * 0.1f);
94 for(
int i = 0; i < num_bins_per_block; ++i)
96 float val = block[i] *
scale;
99 val = fmin(val, hog_info.l2_hyst_threshold());
105 scale = 1.0f / (std::sqrt(sum) + 1e-3f);
108 for(
int i = 0; i < num_bins_per_block; ++i)
111 reinterpret_cast<float *
>(desc(
id))[i] = block[i];
116 template <
typename T,
typename U,
typename V>
121 const size_t num_bins = hog_info.
num_bins();
134 for(
auto sy = cell_size.
height; sy <= shape_height; sy += cell_size.
height)
137 for(
auto sx = cell_size.
width; sx <= shape_width; sx += cell_size.
width)
143 for(
auto y = 0u; y < cell_size.
height; ++y)
145 for(
auto x = 0u; x < cell_size.
width; ++x)
147 int shape_idx = x + row_idx + x_offset + y_offset;
148 mag_cell[elem_idx] = mag[shape_idx];
149 phase_cell[elem_idx] = phase[shape_idx];
153 row_idx += shape_width;
157 std::vector<V> bins(num_bins);
158 hog_orientation_compute(mag_cell, phase_cell, bins, hog_info);
160 for(
size_t i = 0; i < num_bins; ++i)
162 hog_space[cell_idx * num_bins + i] = bins[i];
165 x_offset += cell_size.
width;
169 y_offset += (cell_size.
height * shape_width);
173 template <
typename T>
180 const size_t num_bins = hog_info.
num_bins();
184 const size_t num_bins_per_block_x = cells_per_block.
width * num_bins;
190 int block_y_offset = 0;
193 for(
auto sy = block_size.
height; sy <= shape_height; sy += block_stride.
height)
195 int block_x_offset = 0;
196 for(
auto sx = block_size.
width; sx <= shape_width; sx += block_stride.
width)
198 int cell_y_offset = 0;
202 for(
auto y = 0u; y < cells_per_block.
height; ++y)
204 for(
auto x = 0u; x < num_bins_per_block_x; ++x)
206 int idx = x + cell_y_offset + block_x_offset + block_y_offset;
207 block[elem_idx] = hog_space[idx];
211 cell_y_offset += hog_space.
shape().x() * num_bins;
215 hog_block_normalization_compute(block, desc, hog_info, block_idx);
217 block_x_offset += cells_per_block_stride.
width * num_bins;
221 block_y_offset += cells_per_block_stride.
height * num_bins * hog_space.
shape().x();
225 template <
typename T,
typename U>
BorderMode
Methods available to handle borders.
L2-norm followed by clipping.
PhaseType phase_type() const
The type of PhaseType.
Size2D num_cells_per_block_stride() const
Calculates the number of cells per block stride.
Size2D num_cells_per_block() const
Calculates the number of cells for each block.
void hog_orientation_binning(const SimpleTensor< T > &mag, const SimpleTensor< U > &phase, SimpleTensor< V > &hog_space, const HOGInfo &hog_info)
DATA_TYPE sum(__global const DATA_TYPE *input)
Calculate sum of a vector.
Store the HOG's metadata.
const Size2D & cell_size() const
The cell size in pixels.
1 channel, 1 F32 per channel
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
TensorShape shape() const override
Shape of the tensor.
const Size2D & block_stride() const
The block stride in pixels.
This file contains all available output stages for GEMMLowp on OpenCL.
size_t height
Height of the image region or rectangle.
SimpleTensor< T > hog_descriptor(const SimpleTensor< U > &src, BorderMode border_mode, U constant_border_value, const HOGInfo &hog_info)
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Simple tensor object that stores elements in a consecutive chunk of memory.
SimpleTensor< T > scale(const SimpleTensor< T > &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy, bool ceil_policy_scale)
x and y gradient dimension
size_t width
Width of the image region or rectangle.
HOGNormType
Normalization type for Histogram of Oriented Gradients (HOG)
Class for specifying the size of an image or rectangle.
Store the tensor's metadata.
size_t num_bins() const
The number of histogram bins for each cell.
const Size2D & block_size() const
The block size in pixels.
size_t area() const
The area of the image or rectangle calculated as (width * height)
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
convolution configure & src
void hog_block_normalization(SimpleTensor< T > &desc, const SimpleTensor< T > &hog_space, const HOGInfo &hog_info)