Function mindspore::dataset::Subtract

Function Documentation

bool mindspore::dataset::Subtract(const LiteMat &src_a, const LiteMat &src_b, LiteMat *dst)

Given image A and image B and calculate the difference of them (A - B). This is an element by element operation by subtracting corresponding elements of inputs.

Parameters
  • src_a[in] Input image data.

  • src_b[in] Input image data.

  • dst[in] The difference of input images.

Returns

Return true if transform successfully.

样例
std::vector<uint8_t> mat1 = {3, 3, 3, 3};
LiteMat lite_mat_src;
lite_mat_src.Init(2, 2, 1, mat1.data(), LDataType::UINT8);

std::vector<uint8_t> mat2 = {2, 2, 2, 2};
LiteMat lite_mat_src2;
lite_mat_src2.Init(2, 2, 1, mat2.data(), LDataType::UINT8);

/* Calculate the difference of images */
LiteMat diff;
Subtract(lite_mat_src, lite_mat_src2, &diff);
for (int i = 0; i < diff.height_; i++) {
  for (int j = 0; j < diff.width_; j++) {
    std::cout << std::to_string(diff.ptr<uint8_t>(i)[j]) << ", ";
  }
  std::cout << std::endl;
}