| 141 | |
| 142 | |
| 143 | void rescale_and_normalize( |
| 144 | const uint8_t *image_src, |
| 145 | float *output_buffer, |
| 146 | int image_width, int image_height, int image_channels, |
| 147 | bool do_rescale, |
| 148 | float rescale_factor, |
| 149 | bool do_normalize, |
| 150 | float image_mean, |
| 151 | float image_std |
| 152 | ){ |
| 153 | |
| 154 | // tHE _fuse_mean_and_rescale_factor |
| 155 | if(do_rescale && do_normalize){ |
| 156 | image_mean *= 1.0f/(rescale_factor); |
| 157 | image_std *= 1.0f/(rescale_factor); |
| 158 | do_rescale = false; |
| 159 | } |
| 160 | |
| 161 | if(do_normalize){ |
| 162 | for(int c = 0; c < image_channels; c++){ |
| 163 | for(int h = 0; h < image_height; h++){ |
| 164 | for(int w = 0; w < image_width; w++){ |
| 165 | int idx = c * image_height * image_width + h * image_width + w; |
| 166 | output_buffer[idx] = (static_cast<float>(image_src[idx]) - image_mean) / image_std; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | }else if(do_rescale){ |
| 171 | for(int c = 0; c < image_channels; c++){ |
| 172 | for(int h = 0; h < image_height; h++){ |
| 173 | for(int w = 0; w < image_width; w++){ |
| 174 | int idx = c * image_height * image_width + h * image_width + w; |
| 175 | output_buffer[idx] = static_cast<float>(image_src[idx]) * rescale_factor; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | |
| 182 | |
| 183 | } |
| 184 | |
| 185 | // Auto-dispatching optimized version that selects best implementation at runtime |
| 186 | void rescale_and_normalize_optimized( |
no outgoing calls
no test coverage detected