【发布时间】:2016-07-28 17:04:39
【问题描述】:
我正在尝试将我的 mex 文件中的图像输出回我的 matlab 文件,但是当我在 matlab 中打开它时它不正确。
带有mex文件的输出图像是正确的
我尝试切换 mwSize 的方向以及在new_img.at<int>(j, i) 中交换i 和j;
Mat image = imread(mxArrayToString(prhs[0]));
Mat new_img(H,W, image.type(), Scalar(0));
// some operations on new_img
imshow( "gmm image", image ); //shows the original image
imshow( "gmm1 image", new_img ); //shows the output image
waitKey( 200 ); //both images are the same size as desired
mwSize nd = 2;
mwSize dims[] = {W, H};
plhs[0] = mxCreateNumericArray(nd, dims, mxUINT8_CLASS, mxREAL);
if(plhs == NULL) {
mexErrMsgTxt("Could not create mxArray.\n");
}
char* outMat = (char*) mxGetData( plhs[0]);
for (int i= 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
outMat[i +j*image.rows] = new_img.at<int>(j, i);
}
}
这是在 mat 文件中
gmmMask = GmmMex2(imgName,rect);
imshow(gmmMask); % not the same as the output image. somewhat resembles it, but not correct.
【问题讨论】:
-
new_img是cv::Mat对象吗?从实际代码中看不清楚,因为它没有在任何地方定义。 -
对不起,是的,我修复了编辑问题
-
它不是灰度图像,这或许可以解释原因。我之前尝试过考虑多个渠道,但我无法弄清楚。编辑:如果它现在输出灰度图像也很好
-
是的,这就解释了原因。让我修改我的答案。
标签: c++ matlab opencv image-processing mex