如何从matlab为Triclops结构指定图像值 我有如下C++ cTyWIFF结构: typedef struct TriclopsColorImage { // The number of rows in the image. int nrows; // The number of columns in the image. int ncols; // The row increment of the image. int rowinc; // The pixel data for red band of the image. unsigned char* red; // The pixel data for green band of the image. unsigned char* green; // The pixel data for blue band of the image. unsigned char* blue; } TriclopsColorImage;

如何从matlab为Triclops结构指定图像值 我有如下C++ cTyWIFF结构: typedef struct TriclopsColorImage { // The number of rows in the image. int nrows; // The number of columns in the image. int ncols; // The row increment of the image. int rowinc; // The pixel data for red band of the image. unsigned char* red; // The pixel data for green band of the image. unsigned char* green; // The pixel data for blue band of the image. unsigned char* blue; } TriclopsColorImage;,c++,matlab,C++,Matlab,我有一个图像,它作为prhs[1] 如何正确分配红色、绿色和蓝色字段。给你 TriclopsColorImage colorImage; 我正在做这样的事情: colorImage.nrows=(int) mxGetN(prhs[1]); colorImage.ncols=(int) mxGetM(prhs[1]); colorImage.rowinc=colorImage.ncols*2; colorImage.red=? colorImage.gre

我有一个图像,它作为
prhs[1]
如何正确分配红色、绿色和蓝色字段。给你

TriclopsColorImage colorImage;
我正在做这样的事情:

    colorImage.nrows=(int) mxGetN(prhs[1]);
    colorImage.ncols=(int) mxGetM(prhs[1]);
    colorImage.rowinc=colorImage.ncols*2;
    colorImage.red=?
    colorImage.green=?
    colorImage.blue=?

您必须将图像作为大小
m
-by-
n
-by-3的
uint8
类型传递给mex函数。
例如:

img = imread( 'football.jpg' ); 
myMeFunction( someArg, img ); % note that prhs[1] is the SECOND argument
现在在您的mex中:

colorImage.nrows=(int) mxGetM(prhs[1]); // M is number of rows!
colorImage.ncols=(int) mxGetN(prhs[1]) / 3; // assuming third dimension is three.
// for the colors:
unsigned char* p = (unsigned char*)mxGetData(prhs[1]);    
colorImage.red = p;
colorImage.green = p + colorImage.nrows*colorImage.ncols;
colorImage.blue = p + 2*colorImage.nrows*colorImage.ncols;

请仔细阅读。的说明。

什么是“行增量”?根据triclops Library的说明,Rowinc表示一行开头和下一行开头之间的字节数。在上一个示例中,每个像素每列元素使用16位或2字节,但是在您的答案中,因为源代码是unit8,所以每行的字节数是colorImage.ncols