• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2023 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_COLOR_ADJUST_OP_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_COLOR_ADJUST_OP_H_
18 
19 #include <memory>
20 #include <random>
21 #include <string>
22 #include <vector>
23 
24 #include "minddata/dataset/core/tensor.h"
25 #include "minddata/dataset/kernels/tensor_op.h"
26 #include "minddata/dataset/util/status.h"
27 
28 namespace mindspore {
29 namespace dataset {
30 class RandomColorAdjustOp : public RandomTensorOp {
31  public:
32   // Constructor for RandomColorAdjustOp.
33   // @param s_bright_factor brightness change range start value.
34   // @param e_bright_factor brightness change range end value.
35   // @param s_contrast_factor contrast change range start value.
36   // @param e_contrast_factor contrast change range start value.
37   // @param s_saturation_factor saturation change range end value.
38   // @param e_saturation_factor saturation change range end value.
39   // @param s_hue_factor hue change factor start value, this should be greater than  -0.5.
40   // @param e_hue_factor hue change factor start value, this should be less than  0.5.
41   // @param seed optional seed to pass in to the constructor.
42   // @details the randomly chosen degree is uniformly distributed.
43   RandomColorAdjustOp(float s_bright_factor, float e_bright_factor, float s_contrast_factor, float e_contrast_factor,
44                       float s_saturation_factor, float e_saturation_factor, float s_hue_factor, float e_hue_factor);
45 
46   ~RandomColorAdjustOp() override = default;
47 
48   // Overrides the base class compute function.
49   // Calls multiple transform functions in ImageUtils, this function takes an input tensor.
50   // and transforms its data using openCV, the output memory is manipulated to contain the result.
51   // @return Status The status code returned.
52   Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
53 
Name()54   std::string Name() const override { return kRandomColorAdjustOp; }
55 
56  private:
57   /// \brief Compare two floating point variables. Return true if they are same / very close.
58   static inline bool CmpFloat(const float &a, const float &b, float epsilon = 0.0000000001f) {
59     return (std::fabs(a - b) < epsilon);
60   }
61 
62   float bright_factor_start_;
63   float bright_factor_end_;
64   float contrast_factor_start_;
65   float contrast_factor_end_;
66   float saturation_factor_start_;
67   float saturation_factor_end_;
68   float hue_factor_start_;
69   float hue_factor_end_;
70 };
71 }  // namespace dataset
72 }  // namespace mindspore
73 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_COLOR_ADJUST_OP_H_
74