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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_ROTATION_OP_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_ROTATION_OP_H_ 18 19 #include <memory> 20 #include <random> 21 #include <string> 22 #include <vector> 23 24 #include "minddata/dataset/core/tensor.h" 25 #include "minddata/dataset/kernels/image/image_utils.h" 26 #include "minddata/dataset/kernels/tensor_op.h" 27 #include "minddata/dataset/util/status.h" 28 29 namespace mindspore { 30 namespace dataset { 31 class RandomRotationOp : public RandomTensorOp { 32 public: 33 // Constructor for RandomRotationOp 34 // @param startDegree starting range for random degree 35 // @param endDegree ending range for random degree 36 // @param interpolation DE interpolation mode for rotation 37 // @param expand option for the output image shape to change 38 // @param center coordinate for center of image rotation 39 // @param fill_r R value for the color to pad with 40 // @param fill_g G value for the color to pad with 41 // @param fill_b B value for the color to pad with 42 // @details the randomly chosen degree is uniformly distributed 43 // @details the output shape, if changed, will contain the entire rotated image 44 // @note maybe using unsigned long int isn't the best here according to our coding rules 45 RandomRotationOp(float start_degree, float end_degree, InterpolationMode resample, bool expand, 46 std::vector<float> center, uint8_t fill_r, uint8_t fill_g, uint8_t fill_b); 47 48 ~RandomRotationOp() override = default; 49 50 // Overrides the base class compute function 51 // Calls the rotate function in ImageUtils, this function takes an input tensor 52 // and transforms its data using openCV, the output memory is manipulated to contain the result 53 // @return Status The status code returned 54 Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override; 55 56 Status OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) override; 57 Name()58 std::string Name() const override { return kRandomRotationOp; } 59 60 private: 61 float degree_start_; 62 float degree_end_; 63 std::vector<float> center_; 64 InterpolationMode interpolation_; 65 bool expand_; 66 uint8_t fill_r_; 67 uint8_t fill_g_; 68 uint8_t fill_b_; 69 std::uniform_real_distribution<float> distribution_{-1.0, 1.0}; 70 }; 71 } // namespace dataset 72 } // namespace mindspore 73 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_ROTATION_OP_H_ 74