how to allocate such a matrix?
then i just get only one of the values of the rgb cell, like an rgb is a number for the red a number for the green and a number for the blue. how to fill this matrix so i can get the average of the three rgb numbers?
pixel ** pic;
pic = new pixel*[rows];
for all the rows
pic[row] = new pixel[cols];
now pic[row][col][green] for example
this is woefully inefficient (not a solid block of memory, page faults, cant do .write() or .read() on it, cant memcpy, and more). I strongly advise you instead work in either raw bytes:
pic = new unsigned char[rows*cols*3];
or if you must:
pic = new pixel[rows*cols];
if you want a greyscale image, you have 2 choices
fill in the pic where red=green=blue = average of original rgb
or
make pic = new unsigned char[rows*cols] and put the average in each spot.
see if your library supports single dimensional allocated images instead...