transformImageToMatrix function

Transforms the image to a matrix.