Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# array into MWarray Matlab

Tags:

c#

.net

matlab

I have an MxNx3 matrix and i want to transfer it into matlab using MWArray.
Here is my code, however there is no CTOR for that.
Is there any way to do it?

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);
like image 381
Gilad Avatar asked Apr 08 '13 14:04

Gilad


People also ask

What do you mean by C?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

Why C is called structured programming language?

C is called structured programming language because a program in c language can be divided into small logical functional modules or structures with the help of function procedure.

Who invented Python?

¶ When he began implementing Python, Guido van Rossum was also reading the published scripts from “Monty Python's Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python.


1 Answers

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;

This is what I have found.

There is also a nice tutorial here http://domoreinlesstime.wordpress.com/2013/01/26/access-matlab-from-c/

Please notice that you have the correct refernce to the MWArray.dll file (x64 or x86). I have wasted a day or so on that.

like image 67
Gilad Avatar answered Oct 13 '22 14:10

Gilad