私のmexファイルから画像を私のmatlabファイルに出力しようとしていますが、matlabで開くと画像が正しくありません。画像をmatlabに戻すMex
MEXファイルをwithing出力画像Iが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);
}
}
これは、あなたがこのカラー画像であることに言及しているので、これはあなたが考慮すべき行列の3つのスライスを有することを意味するマットファイル
gmmMask = GmmMex2(imgName,rect);
imshow(gmmMask); % not the same as the output image. somewhat resembles it, but not correct.
'new_img'は' cv :: Mat'オブジェクトですか?これはどこにも定義されていないので、実際のコードからは明らかではありません。 – rayryeng
申し訳ありません、ありがとうございました。それは –
グレースケール画像ではありません。その理由を説明するかもしれません。以前は複数のチャンネルを説明しようとしましたが、わかりませんでした。 編集:今のところグレースケール画像を出力するときれいです –