| 465 | } |
| 466 | |
| 467 | inline void GoldComputeHistogram(float (&histogram)[kHistogramBins], float featRadius, |
| 468 | const RawPyramidType &srcGaussianPyramid, const long3 &currStrides, |
| 469 | const long3 &currShape, int octave, int layer, int currBatch, int r, int c) |
| 470 | { |
| 471 | std::vector<float> tempHistogram(kHistogramBins + 4, 0.f); |
| 472 | |
| 473 | int radius = std::round(featRadius * kOrientationRadius); |
| 474 | |
| 475 | float weightScale = -1.f / (2.f * (featRadius * kOrientationSigma) * (featRadius * kOrientationSigma)); |
| 476 | |
| 477 | auto gaussVal = [&srcGaussianPyramid, &currStrides, &octave, &layer, &currBatch](int row, int col) |
| 478 | { |
| 479 | return util::ValueAt<WT>(srcGaussianPyramid[octave][layer], currStrides, long3{currBatch, row, col}); |
| 480 | }; |
| 481 | |
| 482 | for (int i = -radius; i <= radius; i++) |
| 483 | { |
| 484 | if (r + i <= 0 || r + i >= currShape.y - 1) |
| 485 | { |
| 486 | continue; |
| 487 | } |
| 488 | |
| 489 | for (int j = -radius; j <= radius; j++) |
| 490 | { |
| 491 | if (c + j <= 0 || c + j >= currShape.z - 1) |
| 492 | { |
| 493 | continue; |
| 494 | } |
| 495 | |
| 496 | float dx = gaussVal(r + i + 0, c + j + 1) - gaussVal(r + i + 0, c + j - 1); |
| 497 | float dy = gaussVal(r + i - 1, c + j + 0) - gaussVal(r + i + 1, c + j + 0); |
| 498 | |
| 499 | float angle = std::atan2(dy, dx) * 180.f / M_PI; |
| 500 | float weight = std::exp2f((i * i + j * j) * weightScale); |
| 501 | float magnitude = std::sqrt(dx * dx + dy * dy); |
| 502 | |
| 503 | int bin = std::round(angle * kHistogramBins / 360.f); |
| 504 | |
| 505 | bin = (bin >= kHistogramBins ? bin - kHistogramBins : (bin < 0 ? bin + kHistogramBins : bin)); |
| 506 | |
| 507 | tempHistogram[2 + bin] += weight * magnitude; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | tempHistogram[0] = tempHistogram[2 + kHistogramBins - 2]; |
| 512 | tempHistogram[1] = tempHistogram[2 + kHistogramBins - 1]; |
| 513 | |
| 514 | tempHistogram[2 + kHistogramBins + 0] = tempHistogram[2 + 0]; |
| 515 | tempHistogram[2 + kHistogramBins + 1] = tempHistogram[2 + 1]; |
| 516 | |
| 517 | for (int i = 0; i < kHistogramBins; i++) |
| 518 | { |
| 519 | histogram[i] = (tempHistogram[2 + i - 2] + tempHistogram[2 + i + 2]) * 1.f / 16 |
| 520 | + (tempHistogram[2 + i - 1] + tempHistogram[2 + i + 1]) * 4.f / 16 |
| 521 | + (tempHistogram[2 + i + 0]) * 6.f / 16; |
| 522 | } |
| 523 | } |
| 524 |
no test coverage detected