Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to take an image file (eg tiff) and convert it to a spreadsheet (csv, or whatever) such that each pixel becomes a cell with a numeric value for that pixel.

I have googled it, and everyone is trying to sell me OCR software, that is certainly not what I want.

I will be editing the image beforehand, so can convert it to any format required, and can crop it down to a managable size.

It's mainly greyscale I'm interested in, and could do the little bit of colour that I will need as 3 separate files (one per colour channel) .

I will be doing statistical analysis on the spreadsheet later. I could likelly knock somthing together in java to do it, especially given that this is a proof of concept for a (much) later programming project, but that really feels like far too much hastle for what should be a simple task.

share|improve this question
If you say you can do Java, why not. It's not too much of an overhead, although other programming languages could probably do it in less lines of code. I don't think you'll get a readymade solution for this. You can take a look at ImageMagick's interfaces for different programming languages. –  slhck Jun 4 '11 at 10:41
I'll just put this as a comment unless you ask for it as an answer, but using python and the PIL library. you can get to a pixel value in 3 lines of code 1) Import the library 2) open the file 3) getpixel. Everything else is just bookkeeping. –  Dennis Jun 4 '11 at 11:10
Having no idea what python code even looks like let alone how to code it, I personally will give that one a miss, but I'm sure it may work well for others. I am currently in the middle of finding a java editor so I can see if I can remeber how to use it. –  Thingomy Jun 5 '11 at 14:32
add comment

2 Answers

up vote 1 down vote accepted

It's not too complicated. Here's an approach in Java. You'd just need to write this to CSV.. just simple writing to a file.

for (int x = 0; x < image.getWidth(); ++x)
  for (int y = 0; y < image.getHeight(); ++y) {
    int pixel = image.getRGB(x, y);
    int r = (pixel >> 16) & 0xff;
    int g = (pixel >> 8) & 0xff;
    int b = (pixel) & 0xff;

where image is a BufferedImage. You can load a BufferedImage with ImageIO.read(File input);. You'll find this in javax.imageio.ImageIO.

share|improve this answer
This would certainly do the trick, it's been a long time since I've done any java though... –  Thingomy Jun 4 '11 at 11:09
add comment

I would try to use free open-source SAGA GIS, load your image with Module/File/Grid/Import/Image - you will get SAGA grid which you can export as XYZ file which is in fact text file containing X and Y values and the Z grid value of each pixel. This should be waht you neet. SAGA is free. :-) http://www.saga-gis.org/en/index.html

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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