我想使用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) */
根据下面给出的建议,我有一个问题是将无符号字符从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]);
}
}
}