You have row, columns, and at every (row, column) (= (y, x)) location you have a gray level. What are you referring to as "Z"? What does your Z represent? Gray level? If so, then the image array is already what you want. Or were you looking to display the image with surf()?