Program Listing for File image_process.h

Return to documentation for file (include/runtime/include/dataset/lite_cv/image_process.h)

#ifndef IMAGE_PROCESS_H_
#define IMAGE_PROCESS_H_

#include <algorithm>
#include <iostream>
#include <limits>
#include <cmath>
#include <vector>

#include "lite_cv/lite_mat.h"

namespace mindspore {
namespace dataset {

#define CV_PI 3.1415926535897932384626433832795
#define IM_TOOL_EXIF_ORIENTATION_0_DEG 1
#define IM_TOOL_EXIF_ORIENTATION_0_DEG_MIRROR 2
#define IM_TOOL_EXIF_ORIENTATION_180_DEG 3
#define IM_TOOL_EXIF_ORIENTATION_180_DEG_MIRROR 4
#define IM_TOOL_EXIF_ORIENTATION_90_DEG_MIRROR 5
#define IM_TOOL_EXIF_ORIENTATION_90_DEG 6
#define IM_TOOL_EXIF_ORIENTATION_270_DEG_MIRROR 7
#define IM_TOOL_EXIF_ORIENTATION_270_DEG 8
#define NUM_OF_RGB_CHANNELS 9
#define IM_TOOL_DATA_TYPE_FLOAT (1)
#define IM_TOOL_DATA_TYPE_UINT8 (2)
#define IM_TOOL_RETURN_STATUS_SUCCESS (0)
#define IM_TOOL_RETURN_STATUS_INVALID_INPUT (1)
#define IM_TOOL_RETURN_STATUS_FAILED (2)

#define INT16_CAST(X) \
  static_cast<int16_t>(::std::min(::std::max(static_cast<int>(X + (X >= 0.f ? 0.5f : -0.5f)), -32768), 32767));

enum class PaddBorderType {
  PADD_BORDER_CONSTANT = 0,
  PADD_BORDER_REPLICATE = 1,
  PADD_BORDER_REFLECT_101 = 4,
  PADD_BORDER_DEFAULT = PADD_BORDER_REFLECT_101
};

struct BoxesConfig {
 public:
  std::vector<size_t> img_shape;
  std::vector<int> num_default;
  std::vector<int> feature_size;
  float min_scale;
  float max_scale;
  std::vector<std::vector<float>> aspect_rations;
  std::vector<int> steps;
  std::vector<float> prior_scaling;
};

bool DATASET_API ResizeBilinear(const LiteMat &src, LiteMat &dst, int dst_w, int dst_h);

bool DATASET_API InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType data_type, int w, int h,
                               LiteMat &m);

bool DATASET_API ConvertTo(const LiteMat &src, LiteMat &dst, double scale = 1.0);

bool DATASET_API Crop(const LiteMat &src, LiteMat &dst, int x, int y, int w, int h);

bool DATASET_API SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, const std::vector<float> &mean,
                                        const std::vector<float> &std);

bool DATASET_API Pad(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right,
                     PaddBorderType pad_type, uint8_t fill_b_or_gray = 0, uint8_t fill_g = 0, uint8_t fill_r = 0);

bool DATASET_API ExtractChannel(LiteMat &src, LiteMat &dst, int col);

bool DATASET_API Split(const LiteMat &src, std::vector<LiteMat> &mv);

bool DATASET_API Merge(const std::vector<LiteMat> &mv, LiteMat &dst);

bool DATASET_API Affine(LiteMat &src, LiteMat &out_img, const double M[6], std::vector<size_t> dsize,
                        UINT8_C1 borderValue);

bool DATASET_API Affine(LiteMat &src, LiteMat &out_img, const double M[6], std::vector<size_t> dsize,
                        UINT8_C3 borderValue);

std::vector<std::vector<float>> DATASET_API GetDefaultBoxes(const BoxesConfig config);

void DATASET_API ConvertBoxes(std::vector<std::vector<float>> &boxes,
                              const std::vector<std::vector<float>> &default_boxes, const BoxesConfig config);

std::vector<int> DATASET_API ApplyNms(const std::vector<std::vector<float>> &all_boxes, std::vector<float> &all_scores,
                                      float thres, int max_boxes);

bool DATASET_API WarpAffineBilinear(const LiteMat &src, LiteMat &dst, const LiteMat &M, int dst_w, int dst_h,
                                    PaddBorderType borderType, std::vector<uint8_t> &borderValue);

bool DATASET_API WarpPerspectiveBilinear(const LiteMat &src, LiteMat &dst, const LiteMat &M, int dst_w, int dst_h,
                                         PaddBorderType borderType, std::vector<uint8_t> &borderValue);

bool DATASET_API GetRotationMatrix2D(float x, float y, double angle, double scale, LiteMat &M);

bool DATASET_API GetPerspectiveTransform(std::vector<Point> src_point, std::vector<Point> dst_point, LiteMat &M);

bool DATASET_API GetAffineTransform(std::vector<Point> src_point, std::vector<Point> dst_point, LiteMat &M);

bool DATASET_API Transpose(const LiteMat &src, LiteMat &dst);

bool DATASET_API GaussianBlur(const LiteMat &src, LiteMat &dst, const std::vector<int> &ksize, double sigmaX,
                              double sigmaY = 0.f, PaddBorderType pad_type = PaddBorderType::PADD_BORDER_DEFAULT);

bool DATASET_API Canny(const LiteMat &src, LiteMat &dst, double low_thresh, double high_thresh, int ksize = 3,
                       bool L2gradient = false);

bool DATASET_API Conv2D(const LiteMat &src, const LiteMat &kernel, LiteMat &dst, LDataType dst_type,
                        PaddBorderType pad_type = PaddBorderType::PADD_BORDER_DEFAULT);

bool DATASET_API ConvRowCol(const LiteMat &src, const LiteMat &kx, const LiteMat &ky, LiteMat &dst, LDataType dst_type,
                            PaddBorderType pad_type = PaddBorderType::PADD_BORDER_DEFAULT);

bool DATASET_API Sobel(const LiteMat &src, LiteMat &dst, int flag_x, int flag_y, int ksize = 3, double scale = 1.0,
                       PaddBorderType pad_type = PaddBorderType::PADD_BORDER_DEFAULT);

bool DATASET_API ConvertRgbToBgr(const LiteMat &src, const LDataType &data_type, int w, int h, LiteMat &mat);

bool DATASET_API ConvertRgbToGray(const LiteMat &src, LDataType data_type, int w, int h, LiteMat &mat);

bool DATASET_API ResizePreserveARWithFiller(LiteMat &src, LiteMat &dst, int h, int w, float (*ratioShiftWShiftH)[3],
                                            float (*invM)[2][3], int img_orientation);

bool DATASET_API HWC2CHW(LiteMat &src, LiteMat &dst);

}  // namespace dataset
}  // namespace mindspore
#endif  // IMAGE_PROCESS_H_