1
$\begingroup$

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:

{
{10,11,14,8,9},
{11,9,15,12,10},
{12,4,7,8,4}
}

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

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

1 Answer 1

3
$\begingroup$

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).

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

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.