Program Listing for File image_process.h

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

#ifndef IMAGE_PROCESS_H_
#define IMAGE_PROCESS_H_

#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>

#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 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 ResizeBilinear(const LiteMat &src, LiteMat &dst, int dst_w, int dst_h);

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

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

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

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

bool 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 ExtractChannel(LiteMat &src, LiteMat &dst, int col);

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

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

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

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

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

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

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

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

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

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

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

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

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

bool 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 Canny(const LiteMat &src, LiteMat &dst, double low_thresh, double high_thresh, int ksize = 3,
           bool L2gradient = false);

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

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

bool 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 ConvertRgbToBgr(const LiteMat &src, const LDataType &data_type, int w, int h, LiteMat &mat);

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

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

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