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