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 #include "minddata/dataset/kernels/image/random_sharpness_op.h"
18
19 #include "minddata/dataset/kernels/image/image_utils.h"
20
21 namespace mindspore {
22 namespace dataset {
23 /// constructor
RandomSharpnessOp(float start_degree,float end_degree)24 RandomSharpnessOp::RandomSharpnessOp(float start_degree, float end_degree)
25 : start_degree_(start_degree), end_degree_(end_degree) {}
26
27 /// main function call for random sharpness : Generate the random degrees
Compute(const std::shared_ptr<Tensor> & input,std::shared_ptr<Tensor> * output)28 Status RandomSharpnessOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
29 IO_CHECK(input, output);
30 float random_double = distribution_(random_generator_);
31 /// get the degree sharpness range
32 /// the way this op works (uniform distribution)
33 /// assumption here is that mDegreesEnd > mDegreeStart so we always get positive number
34 float degree_range = (end_degree_ - start_degree_) / 2;
35 float mid = (end_degree_ + start_degree_) / 2;
36 float alpha = mid + random_double * degree_range;
37 return AdjustSharpness(input, output, alpha);
38 }
39 } // namespace dataset
40 } // namespace mindspore
41