MCPcopy Create free account
hub / github.com/ARM-software/armnn / ResizeBilinearAndNormalize

Function ResizeBilinearAndNormalize

tests/InferenceTestImage.cpp:55–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55std::vector<float> ResizeBilinearAndNormalize(const InferenceTestImage & image,
56 const unsigned int outputWidth,
57 const unsigned int outputHeight,
58 const float scale,
59 const std::array<float, 3>& mean,
60 const std::array<float, 3>& stddev)
61{
62 std::vector<float> out;
63 out.resize(outputWidth * outputHeight * 3);
64
65 // We follow the definition of TensorFlow and AndroidNN: the top-left corner of a texel in the output
66 // image is projected into the input image to figure out the interpolants and weights. Note that this
67 // will yield different results than if projecting the centre of output texels.
68
69 const unsigned int inputWidth = image.GetWidth();
70 const unsigned int inputHeight = image.GetHeight();
71
72 // How much to scale pixel coordinates in the output image to get the corresponding pixel coordinates
73 // in the input image.
74 const float scaleY = armnn::numeric_cast<float>(inputHeight) / armnn::numeric_cast<float>(outputHeight);
75 const float scaleX = armnn::numeric_cast<float>(inputWidth) / armnn::numeric_cast<float>(outputWidth);
76
77 uint8_t rgb_x0y0[3];
78 uint8_t rgb_x1y0[3];
79 uint8_t rgb_x0y1[3];
80 uint8_t rgb_x1y1[3];
81
82 for (unsigned int y = 0; y < outputHeight; ++y)
83 {
84 // Corresponding real-valued height coordinate in input image.
85 const float iy = armnn::numeric_cast<float>(y) * scaleY;
86
87 // Discrete height coordinate of top-left texel (in the 2x2 texel area used for interpolation).
88 const float fiy = floorf(iy);
89 const unsigned int y0 = armnn::numeric_cast<unsigned int>(fiy);
90
91 // Interpolation weight (range [0,1])
92 const float yw = iy - fiy;
93
94 for (unsigned int x = 0; x < outputWidth; ++x)
95 {
96 // Real-valued and discrete width coordinates in input image.
97 const float ix = armnn::numeric_cast<float>(x) * scaleX;
98 const float fix = floorf(ix);
99 const unsigned int x0 = armnn::numeric_cast<unsigned int>(fix);
100
101 // Interpolation weight (range [0,1]).
102 const float xw = ix - fix;
103
104 // Discrete width/height coordinates of texels below and to the right of (x0, y0).
105 const unsigned int x1 = std::min(x0 + 1, inputWidth - 1u);
106 const unsigned int y1 = std::min(y0 + 1, inputHeight - 1u);
107
108 std::tie(rgb_x0y0[0], rgb_x0y0[1], rgb_x0y0[2]) = image.GetPixelAs3Channels(x0, y0);
109 std::tie(rgb_x1y0[0], rgb_x1y0[1], rgb_x1y0[2]) = image.GetPixelAs3Channels(x1, y0);
110 std::tie(rgb_x0y1[0], rgb_x0y1[1], rgb_x0y1[2]) = image.GetPixelAs3Channels(x0, y1);
111 std::tie(rgb_x1y1[0], rgb_x1y1[1], rgb_x1y1[2]) = image.GetPixelAs3Channels(x1, y1);
112

Callers 1

ResizeMethod · 0.85

Calls 6

PutDataFunction · 0.85
resizeMethod · 0.80
GetPixelAs3ChannelsMethod · 0.80
LerpFunction · 0.70
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected