2013-04-08 30 views
6

私はMxNx3行列を持っています。私はMWArrayを使ってmatlabに転送したいと思います。
ここに私のコードですが、CTORはありません。
これを行う方法はありますか?MWarrayへのC#配列Matlab

RGBImage image = _currentImage as RGBImage; 

int height = image.Height; 
int width = image.Width; 

//transform the 1D array of byte into MxNx3 matrix 
byte[, ,] rgbByteImage = new byte[3, height, width]; 
if (image[0].Bpp > 16) 
{ 
    for (int i = 0; i < height; i++) 
    { 
     for (int j = 0, k = 0; k < width; j = j + 3, k++) 
     { 
      rgbByteImage[0, i, k] = image[0].Data[i * width + j]; 
      rgbByteImage[1, i, k] = image[0].Data[i * width + j + 1]; 
      rgbByteImage[2, i, k] = image[0].Data[i * width + j + 2 ]; 
     } 
    } 
} 

MWNumericArray tempArr = new MWNumericArray(rgbByteImage); 

答えて

6
RGBImage image = _currentImage as RGBImage; 

int height = image.Height; 
int width = image.Width; 

//transform the 1D array of byte into MxNx3 matrix 

byte[ , , ] RGBByteImage = new byte[3,height, width]; 

if (image[0].Bpp > 16) 
{ 
    for (int i = 0; i < height; i++) 
    { 
     for (int j = 0, k = 0; k < width; j = j + 3, k++) 
     { 
      RGBByteImage[0, i, k] = image[0].Data[3 * i * width + j]; 
      RGBByteImage[1, i, k] = image[0].Data[3 * i * width + j + 1]; 
      RGBByteImage[2, i, k] = image[0].Data[3 * i * width + j + 2]; 
     } 
    } 
} 

MWNumericArray matrix = null; 
matrix = new MWNumericArray(MWArrayComplexity.Real, MWNumericType.Int8, 3,height, width); 
matrix = RGBByteImage; 

これは私が発見したものです。

素敵なチュートリアルはここにもあります http://domoreinlesstime.wordpress.com/2013/01/26/access-matlab-from-c/

あなたはMWArray.dllファイル(x64のまたはx86)への正しいrefernceを持っていることに注意してください。私は1日かそれ以上の時間を無駄にしてしまった。