| 32 | namespace t = ::testing; |
| 33 | |
| 34 | static void Normalize(std::vector<uint8_t> &hDst, int dstRowStride, const std::vector<uint8_t> &hSrc, int srcRowStride, |
| 35 | nvcv::Size2D size, nvcv::ImageFormat fmt, const std::vector<float> &hBase, int baseRowStride, |
| 36 | nvcv::Size2D baseSize, nvcv::ImageFormat baseFormat, const std::vector<float> &hScale, |
| 37 | int scaleRowStride, nvcv::Size2D scaleSize, nvcv::ImageFormat scaleFormat, |
| 38 | const float globalScale, const float globalShift, const float epsilon, const uint32_t flags) |
| 39 | { |
| 40 | using FT = float; |
| 41 | |
| 42 | for (int i = 0; i < size.h; i++) |
| 43 | { |
| 44 | const int bi = baseSize.h == 1 ? 0 : i; |
| 45 | const int si = scaleSize.h == 1 ? 0 : i; |
| 46 | |
| 47 | for (int j = 0; j < size.w; j++) |
| 48 | { |
| 49 | const int bj = baseSize.w == 1 ? 0 : j; |
| 50 | const int sj = scaleSize.w == 1 ? 0 : j; |
| 51 | |
| 52 | for (int k = 0; k < fmt.numChannels(); k++) |
| 53 | { |
| 54 | const int bk = (baseFormat.numChannels() == 1 ? 0 : k); |
| 55 | const int sk = (scaleFormat.numChannels() == 1 ? 0 : k); |
| 56 | |
| 57 | FT mul; |
| 58 | |
| 59 | if (flags & CVCUDA_NORMALIZE_SCALE_IS_STDDEV) |
| 60 | { |
| 61 | FT s = hScale.at(si * scaleRowStride + sj * scaleFormat.numChannels() + sk); |
| 62 | FT x = s * s + epsilon; |
| 63 | mul = FT{1} / std::sqrt(x); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | mul = hScale.at(si * scaleRowStride + sj * scaleFormat.numChannels() + sk); |
| 68 | } |
| 69 | |
| 70 | FT res = std::rint((hSrc.at(i * srcRowStride + j * fmt.numChannels() + k) |
| 71 | - hBase.at(bi * baseRowStride + bj * baseFormat.numChannels() + bk)) |
| 72 | * mul * globalScale |
| 73 | + globalShift); |
| 74 | |
| 75 | hDst.at(i * dstRowStride + j * fmt.numChannels() + k) = res < 0 ? 0 : (res > 255 ? 255 : res); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static uint32_t normalScale = 0; |
| 82 | static uint32_t scaleIsStdDev = CVCUDA_NORMALIZE_SCALE_IS_STDDEV; |
no test coverage detected