| 250 | typename image_type |
| 251 | > |
| 252 | void load_impl ( |
| 253 | const image_type& img |
| 254 | ) |
| 255 | { |
| 256 | // Note that we keep a border of 1 pixel all around the image so that we don't have |
| 257 | // to worry about running outside the image when computing the horizontal and vertical |
| 258 | // gradients. |
| 259 | |
| 260 | // Note also that we have a border of unused cells around the hist_cells array so that we |
| 261 | // don't have to worry about edge effects when doing the interpolation in the main loop |
| 262 | // below. |
| 263 | |
| 264 | |
| 265 | // check if the window is just too small |
| 266 | if (img.nr() < min_size || img.nc() < min_size) |
| 267 | { |
| 268 | // If the image is smaller than our windows then there aren't any descriptors at all! |
| 269 | num_block_rows = 0; |
| 270 | num_block_cols = 0; |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | // Make sure we have the right number of cell histograms and that they are |
| 275 | // all set to zero. |
| 276 | hist_cells.set_size((img.nr()-2)/cell_size+2, (img.nc()-2)/cell_size+2); |
| 277 | for (long r = 0; r < hist_cells.nr(); ++r) |
| 278 | { |
| 279 | for (long c = 0; c < hist_cells.nc(); ++c) |
| 280 | { |
| 281 | hist_cells[r][c].zero(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
| 286 | // loop over all the histogram cells and fill them out |
| 287 | for (long rh = 1; rh < hist_cells.nr()-1; ++rh) |
| 288 | { |
| 289 | for (long ch = 1; ch < hist_cells.nc()-1; ++ch) |
| 290 | { |
| 291 | // Fill out the current histogram cell. |
| 292 | // First, figure out the row and column offsets into the image for the current histogram cell. |
| 293 | const long roff = (rh-1)*cell_size + 1; |
| 294 | const long coff = (ch-1)*cell_size + 1; |
| 295 | |
| 296 | for (long r = 0; r < (long)cell_size; ++r) |
| 297 | { |
| 298 | for (long c = 0; c < (long)cell_size; ++c) |
| 299 | { |
| 300 | unsigned long left; |
| 301 | unsigned long right; |
| 302 | unsigned long top; |
| 303 | unsigned long bottom; |
| 304 | |
| 305 | assign_pixel(left, img(r+roff,c+coff-1)); |
| 306 | assign_pixel(right, img(r+roff,c+coff+1)); |
| 307 | assign_pixel(top, img(r+roff-1,c+coff)); |
| 308 | assign_pixel(bottom, img(r+roff+1,c+coff)); |
| 309 | |