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ファイルからunsigned charを多次元配列に変換する際に問題があります。しかし、私はデータを c[] w[] h[] の形式で表現しなければなりません。次のように、赤、緑、青の情報をどのように c[] に表現するのか混乱しています。私はこれがそれを表現する正しい方法であるかどうか混乱しています(この関数は const unsigned char[] を取得することを目的としていることがわかります)、3次元の 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]);
}
}
}