I would like to simply convert a grayscale tif file to a text file, in which the numbers in a 2-dimensional array represent the gray values of each pixel, e.g. the result should be:


with the numbers representing the gray values. I tried with Raster, but this did not work.

  • $\begingroup$ Look up ImageData $\endgroup$
    – Bill
    Mar 1, 2017 at 16:33

1 Answer 1


It's pretty simple. First import the image.

img = Import[FileNameJoin[{$HomeDirectory, "Desktop", "moon.tiff"}]]

Then export it as byte data (integers in the range 0 - 255).

  FileNameJoin[{$HomeDirectory, "Desktop", "moon.csv"}], 
  ImageData[img, "Byte"]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.