• caffe RandomHue和RandomSaturation


    https://www.cnblogs.com/wangyblzu/p/5710715.html

    HSV和RGB一样是一种图像的颜色模型,h表示色调,s表示饱和度

     1.RandomHue

    void RandomHue(const cv::Mat& in_img, cv::Mat* out_img,
                   const float hue_prob, const float hue_delta) {
      float prob;
      caffe_rng_uniform(1, 0.f, 1.f, &prob);
      if (prob < hue_prob) {
       以一定概率进行色调调整 CHECK_GE(hue_delta,
    0) << "hue_delta must be non-negative."; float delta; caffe_rng_uniform(1, -hue_delta, hue_delta, &delta); AdjustHue(in_img, delta, out_img); } else { *out_img = in_img; } }

    需要先把rgb图转成hsv图,然后对第一个通道也就是h的通道的每个值加上delta,最后再换转成rgb图

    void AdjustHue(const cv::Mat& in_img, const float delta, cv::Mat* out_img) {
      if (fabs(delta) > 0) {
        // Convert to HSV colorspae.
        cv::cvtColor(in_img, *out_img, CV_BGR2HSV);
    
        // Split the image to 3 channels.
        vector<cv::Mat> channels;
        cv::split(*out_img, channels);
    
        // Adjust the hue.
        channels[0].convertTo(channels[0], -1, 1, delta);
        cv::merge(channels, *out_img);
    
        // Back to BGR colorspace.
        cvtColor(*out_img, *out_img, CV_HSV2BGR);
      } else {
        *out_img = in_img;
      }
    }

    2.RandomSaturation

    void RandomContrast(const cv::Mat& in_img, cv::Mat* out_img,
        const float contrast_prob, const float lower, const float upper) {
      float prob;
      caffe_rng_uniform(1, 0.f, 1.f, &prob);
      if (prob < contrast_prob) {
        CHECK_GE(upper, lower) << "contrast upper must be >= lower.";
        CHECK_GE(lower, 0) << "contrast lower must be non-negative.";
        float delta;
        caffe_rng_uniform(1, lower, upper, &delta);
        AdjustContrast(in_img, delta, out_img);
      } else {
        *out_img = in_img;
      }
    }

    RandomSaturation做的是让通道里每个像素值乘以一个数,RandomHue是加一个数,这和 RandomBrightness和RandomContrast的区别是一样的

    void AdjustContrast(const cv::Mat& in_img, const float delta,
                        cv::Mat* out_img) {
      if (fabs(delta - 1.f) > 1e-3) {
        in_img.convertTo(*out_img, -1, delta, 0);
      } else {
        *out_img = in_img;
      }
    }
  • 相关阅读:
    android之Animation
    A. Puzzles CodeForces Round #196 (Div.2)
    HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6
    UVa 11464 Even Parity 偶数矩阵
    LA 3635 Pie 派 NWERC 2006
    UVa 11520 Fill the Square 填充正方形
    UVa 11384 Help is needed for Dexter 正整数序列
    HDU 4639 Hehe 2013 Multi-University Training Contest 4
    HDU 4627 The Unsolvable Problem 2013 Multi-University Training Contest 3
    HDU 4608 I-number 2013 Multi-University Training Contest 1
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/9167480.html
Copyright © 2020-2023  润新知