1

我想使用 Matlab 编码器的输出进行图像处理。我从 Matlab 编码器创建了一个 c++ 输出,我想使用此代码将其集成到其他应用程序中。问题是我们不确切知道 Matlab 编码器如何将图像矩阵生成为const unsigned char[...]。如果有任何可能检查它的创建方式,那将是非常有帮助的。这样我们就可以将图像创建为 unsigned char[..],以同样的方式将其转换回图像。

这是matlab生成的代码

 * multiplyImage.c
 *
 * Code generation for function 'multiplyImage'
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "multiplyImage.h"

/* Function Declarations */
static double rt_roundd_snf(double u);

/* Function Definitions */
static double rt_roundd_snf(double u)
{
  double y;
  if (fabs(u) < 4.503599627370496E+15) {
    if (u >= 0.5) {
      y = floor(u + 0.5);
    } else if (u > -0.5) {
      y = u * 0.0;
    } else {
      y = ceil(u - 0.5);
    }
  } else {
    y = u;
  }

  return y;
}

void multiplyImage(const unsigned char img[2115216], double parameter, unsigned
                   char imgout[2115216])
{
  int i0;
  double d0;
  unsigned char u0;

  /*  implements a function that multiplies an image with a parameter */
  for (i0 = 0; i0 < 2115216; i0++) {
    d0 = rt_roundd_snf(parameter * (double)img[i0]);
    if (d0 < 256.0) {
      if (d0 >= 0.0) {
        u0 = (unsigned char)d0;
      } else {
        u0 = 0;
      }
    } else if (d0 >= 256.0) {
      u0 = MAX_uint8_T;
    } else {
      u0 = 0;
    }

    imgout[i0] = u0;
  }
}

/* End of code generation (multiplyImage.c) */

根据以下给出的建议,我在将 unsigned char 从 cpp 文件转换为多维数组时遇到问题。但是我必须以 c[] w[] h[] 的格式表示数据,我很困惑如何将红色、绿色、蓝色信息表示为 c[]。我很困惑这是表示它的正确方法(如您所见,此函数旨在获取 const unsigned char[])并创建具有三维 c[] w[] h[] 矩阵的输出。任何帮助都会很棒

double Marvin_To_UnsignedChar::Convert_To_Marvin_Image(const unsigned char input[])
{
    int Initial_Color;
    for (int Initial_Height = 0; Initial_Height < Height; ++Initial_Height)
    {
        for (int Initial_Width = 0; Initial_Width < Width; ++Initial_Width)
        {
            int red  [Initial_Height * Width + Initial_Width] = input[Initial_Width * Height + Initial_Height];
            int green[Initial_Height * Width + Initial_Width] = input[Height * Width + Initial_Width * Height + Initial_Height];
            int blue [Initial_Height * Width + Initial_Width] = input[2 * Height * Width + Initial_Width * Height + Initial_Width * Height + 1];
            int color((red[Initial_Height * Width + Initial_Width]) (green[Initial_Height * Width + Initial_Width]) (blue[Initial_Height * Width + Initial_Width]));
            double Marvin_Matrix([color][Width][Height]);
            return Marvin_Matrix([color][Width][Height]);
        }
    }
}
4

0 回答 0