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 #include "minddata/dataset/kernels/image/random_posterize_op.h"
18
19 #include <opencv2/imgcodecs.hpp>
20
21 #include "minddata/dataset/util/random.h"
22
23 namespace mindspore {
24 namespace dataset {
25
26 const std::vector<uint8_t> RandomPosterizeOp::kBitRange = {4, 8};
27
RandomPosterizeOp(const std::vector<uint8_t> & bit_range)28 RandomPosterizeOp::RandomPosterizeOp(const std::vector<uint8_t> &bit_range)
29 : PosterizeOp(bit_range[0]), bit_range_(bit_range) {
30 rnd_.seed(GetSeed());
31 is_deterministic_ = false;
32 }
33
Compute(const std::shared_ptr<Tensor> & input,std::shared_ptr<Tensor> * output)34 Status RandomPosterizeOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
35 CHECK_FAIL_RETURN_UNEXPECTED(input != nullptr, "RandomPosterizeOp: parameter input is nullptr");
36 bit_ = (bit_range_[0] == bit_range_[1]) ? bit_range_[0]
37 : std::uniform_int_distribution<uint8_t>(bit_range_[0], bit_range_[1])(rnd_);
38 return PosterizeOp::Compute(input, output);
39 }
40 } // namespace dataset
41 } // namespace mindspore
42