# Revision history [back]

### read image as array - save array as image

Hello , I just started to study openCV and I am trying to figure how to properly read the image as array.

First of all , when I am loading the image using imread , what is the type ? Always unsigned char?

So,for example, I am trying to do:

...
Mat  grayImage;
...

unsigned char *myData = grayImage.data;
int width = grayImage.cols;
int height = grayImage.rows;

for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
cout << "Mat[ " << i * width + j << " ] = " << (myData[ i * width + j ]) << "\t";
}
cout << endl;
}


I am receiving as output symbols and letters.

Also, if I want to store an array as an image what steps must I follow?

### read image as array - save array as image

Hello , I just started to study openCV and I am trying to figure how to properly read the image as array.

First of all , when I am loading the image using imread , what is the type ? Always unsigned char?

So,for example, I am trying to do:

...
Mat  grayImage;
...

unsigned char *myData = grayImage.data;
int width = grayImage.cols;
int height = grayImage.rows;

for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
cout << "Mat[ " << i * width + j << " ] = " << (myData[ i * width + j ]) << "\t";
}
cout << endl;
}


I am receiving as output symbols and letters.

Also, if I want to store an array as an image what steps must I follow?

(I forgot to mention that I want to use pointers in order to access data)