1 /** 2 * Copyright 2019 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 TensorOp { 31 public: 32 static const uint32_t kDefSeed; 33 34 // Constructor for RandomColorAdjustOp. 35 // @param s_bright_factor brightness change range start value. 36 // @param e_bright_factor brightness change range end value. 37 // @param s_contrast_factor contrast change range start value. 38 // @param e_contrast_factor contrast change range start value. 39 // @param s_saturation_factor saturation change range end value. 40 // @param e_saturation_factor saturation change range end value. 41 // @param s_hue_factor hue change factor start value, this should be greater than -0.5. 42 // @param e_hue_factor hue change factor start value, this should be less than 0.5. 43 // @param seed optional seed to pass in to the constructor. 44 // @details the randomly chosen degree is uniformly distributed. 45 RandomColorAdjustOp(float s_bright_factor, float e_bright_factor, float s_contrast_factor, float e_contrast_factor, 46 float s_saturation_factor, float e_saturation_factor, float s_hue_factor, float e_hue_factor); 47 48 ~RandomColorAdjustOp() override = default; 49 50 // Overrides the base class compute function. 51 // Calls multiple transform functions in ImageUtils, this function takes an input tensor. 52 // and transforms its data using openCV, the output memory is manipulated to contain the result. 53 // @return Status The status code returned. 54 Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override; 55 Name()56 std::string Name() const override { return kRandomColorAdjustOp; } 57 58 private: 59 std::mt19937 rnd_; 60 float bright_factor_start_; 61 float bright_factor_end_; 62 float contrast_factor_start_; 63 float contrast_factor_end_; 64 float saturation_factor_start_; 65 float saturation_factor_end_; 66 float hue_factor_start_; 67 float hue_factor_end_; 68 // Compare two floating point variables. Return true if they are same / very close. 69 inline bool CmpFloat(const float &a, const float &b, float epsilon = 0.0000000001f) const { 70 return (std::fabs(a - b) < epsilon); 71 } 72 }; 73 } // namespace dataset 74 } // namespace mindspore 75 76 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_COLOR_ADJUST_OP_H_ 77