1 /** 2 * Copyright 2020 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 17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_RANDOM_COLOR_OP_H 18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_RANDOM_COLOR_OP_H 19 20 #include <memory> 21 #include <random> 22 #include <vector> 23 #include <string> 24 #include <opencv2/imgproc/imgproc.hpp> 25 #include "minddata/dataset/core/tensor.h" 26 #include "minddata/dataset/core/cv_tensor.h" 27 #include "minddata/dataset/kernels/tensor_op.h" 28 #include "minddata/dataset/util/status.h" 29 #include "minddata/dataset/util/random.h" 30 31 namespace mindspore { 32 namespace dataset { 33 34 /// \class RandomColorOp random_color_op.h 35 /// \brief Blends an image with its grayscale version with random weights 36 /// t and 1 - t generated from a given range. 37 /// If the range is trivial then the weights are determinate and 38 /// t equals the bound of the interval 39 class RandomColorOp : public TensorOp { 40 public: 41 RandomColorOp() = default; 42 43 ~RandomColorOp() = default; 44 /// \brief Constructor 45 /// \param[in] t_lb lower bound for the random weights 46 /// \param[in] t_ub upper bound for the random weights 47 RandomColorOp(float t_lb, float t_ub); 48 /// \brief the main function performing computations 49 /// \param[in] in 2- or 3- dimensional tensor representing an image 50 /// \param[out] out 2- or 3- dimensional tensor representing an image 51 /// with the same dimensions as in 52 Status Compute(const std::shared_ptr<Tensor> &in, std::shared_ptr<Tensor> *out) override; 53 /// \brief returns the name of the op Name()54 std::string Name() const override { return kRandomColorOp; } 55 56 private: 57 std::mt19937 rnd_; 58 std::uniform_real_distribution<float> dist_; 59 float t_lb_; 60 float t_ub_; 61 }; 62 } // namespace dataset 63 } // namespace mindspore 64 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_RANDOM_COLOR_OP_H 65