gpt4 book ai didi

c++ - 如何从 matlab 将图像值分配给 Triclops 结构

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:54:38 26 4
gpt4 key购买 nike

我使用以下 C++ typedef 结构:

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;

我有一张图像作为 prhs[1] 传递给 mex 函数如何正确分配红色、绿色和蓝色的字段。我这里有

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 函数。< br/>例如:

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;

仔细阅读mxGetN的描述.

关于c++ - 如何从 matlab 将图像值分配给 Triclops 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com