tensorflow/lite/tools/evaluation/stages/image_preprocessing_stage.cc
// Normalizes the image data to a specific range with mean and scale.
Normalizes the image data to a specific range with mean and scale.
Normalizes the image data to a specific range with mean and scale .
inline void Normalize(ImageData* image_data,
                      const NormalizationParams& params) {
  float scale = params.scale();
  float* data_end = image_data->data->data() + image_data->data->size();
  if (params.has_channelwise_mean()) {
    float mean = params.channelwise_mean();
    for (float* data = image_data->data->data(); data < data_end; ++data) {
      *data = (*data - mean) * scale;
    }
  } else {
    float r_mean = params.means().r_mean();
    float g_mean = params.means().g_mean();
    float b_mean = params.means().b_mean();
    for (float* data = image_data->data->data(); data < data_end;) {
      *data = (*data - r_mean) * scale;
      ++data;
      *data = (*data - g_mean) * scale;
      ++data;
      *data = (*data - b_mean) * scale;
      ++data;
    }
  }
}
inline void Normalize ( ImageData * image_data , const NormalizationParams & params ) { float scale = params . scale ( ) ; float * data_end = image_data -> data -> data ( ) + image_data -> data -> size ( ) ; if ( params . has_channelwise_mean ( ) ) { float mean = params . channelwise_mean ( ) ; for ( float * data = image_data -> data -> data ( ) ; data < data_end ; ++ data ) { * data = ( * data - mean ) * scale ; } } else { float r_mean = params . means ( ) . r_mean ( ) ; float g_mean = params . means ( ) . g_mean ( ) ; float b_mean = params . means ( ) . b_mean ( ) ; for ( float * data = image_data -> data -> data ( ) ; data < data_end ; ) { * data = ( * data - r_mean ) * scale ; ++ data ; * data = ( * data - g_mean ) * scale ; ++ data ; * data = ( * data - b_mean ) * scale ; ++ data ; } } }
Normalizes the image data to a specific range with mean and scale.
Normalizes the image data to a specific range with mean and scale .