MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / Normalize

Function Normalize

tests/cvcuda/system/TestOpNormalize.cpp:34–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace t = ::testing;
33
34static 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
81static uint32_t normalScale = 0;
82static uint32_t scaleIsStdDev = CVCUDA_NORMALIZE_SCALE_IS_STDDEV;

Callers 1

TEST_PFunction · 0.70

Calls 3

sqrtFunction · 0.85
numChannelsMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected