• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_sharpness_op.h"
18 #include "minddata/dataset/kernels/image/sharpness_op.h"
19 #include "minddata/dataset/core/cv_tensor.h"
20 #include "minddata/dataset/util/random.h"
21 #include "minddata/dataset/util/status.h"
22 
23 namespace mindspore {
24 namespace dataset {
25 
26 const float RandomSharpnessOp::kDefStartDegree = 0.1;
27 const float RandomSharpnessOp::kDefEndDegree = 1.9;
28 
29 /// constructor
RandomSharpnessOp(float start_degree,float end_degree)30 RandomSharpnessOp::RandomSharpnessOp(float start_degree, float end_degree)
31     : start_degree_(start_degree), end_degree_(end_degree) {
32   rnd_.seed(GetSeed());
33   is_deterministic_ = false;
34 }
35 
36 /// main function call for random sharpness : Generate the random degrees
Compute(const std::shared_ptr<Tensor> & input,std::shared_ptr<Tensor> * output)37 Status RandomSharpnessOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
38   IO_CHECK(input, output);
39   float random_double = distribution_(rnd_);
40   /// get the degree sharpness range
41   /// the way this op works (uniform distribution)
42   /// assumption here is that mDegreesEnd > mDegreeStart so we always get positive number
43   float degree_range = (end_degree_ - start_degree_) / 2;
44   float mid = (end_degree_ + start_degree_) / 2;
45   alpha_ = mid + random_double * degree_range;
46 
47   return SharpnessOp::Compute(input, output);
48 }
49 }  // namespace dataset
50 }  // namespace mindspore
51