0

I am trying to get the grayscale image values 0-255 of the 512x512 image of lena. Some have suggested using Matlab, however I do not have Matlab. Has anyone used Gimp for this?

Zeus
  • 1,401
  • 16
  • 27
  • One solution would be to load the image into a BufferedImage object in Java, convert to grayscale (as shown here: http://stackoverflow.com/questions/9131678/convert-a-rgb-image-to-grayscale-image-reducing-the-memory-in-java) and then query the individual pixels using the getRGB method. But this might be too roundabout.... – eboix Jun 23 '15 at 18:09
  • I already have the image in grayscale. – Zeus Jun 23 '15 at 18:16
  • Then it's even easier. If you know Java, you can open up the image using something like: http://alvinalexander.com/blog/post/java/open-read-image-file-java-imageio-class. And then you can query individual pixels using the getRGB method. R value should equal G value, which should equal B value. Let me know if this doesn't work/if you don't know Java. – eboix Jun 23 '15 at 18:19
  • Never programmed in Java. The link does not work. – Zeus Jun 23 '15 at 18:21
  • OK. Do you want an array of all the values for the image, or just the values of individual pixels? – eboix Jun 23 '15 at 18:22
  • I want all the values so I can load them into a two-dimensional array in Fortran. – Zeus Jun 23 '15 at 18:22
  • 1
    OK, so if you know how to do this with MATLAB then one way to do this would be to use Octave, which is free and can be downloaded here: http://www.gnu.org/software/octave/download.html . The `imread` command that I'm guessing you would have used with MATLAB is compatible with Octave, so you can use the same command. Don't know if this is the easiest way to do this, but it should work. – eboix Jun 23 '15 at 18:26
  • Otherwise, an easier way is just to use some online utility like http://manytools.org/hacker-tools/image-to-byte-array . This should be good, as long as you don't want to automate the process and do this for many images. – eboix Jun 23 '15 at 18:28
  • Bugger, file size too large nonsense – Zeus Jun 23 '15 at 18:33
  • I am trying to use octave. I am supposed to get a gui after I type `octave` on the terminal, but the gui is not displaying. I have installed GNU Octave, version 3.8.1 and the gui should start by default. – Zeus Jun 23 '15 at 19:03
  • You could try using the command-line program ImageMagick as described in [this question](http://stackoverflow.com/questions/13317753/convert-rgb-to-grayscale-in-imagemagick-command-line). – eigenchris Jun 23 '15 at 20:31
  • I think the OP already has a grayscale image. He just wants to get an array of pixel values. – eboix Jun 23 '15 at 21:38

2 Answers2

1

Just use ImageMagick. It is installed on most Linux distros and available for OSX and Windows:

convert lena.jpg -colorspace gray -depth 8 txt:-
Mark Setchell
  • 146,975
  • 21
  • 182
  • 306
0

The octave solution is to read the image using

im = imread("lena512.jpg");

The image im can then be shown using imshow (im).

Conversion to grayscale can be performed using

lenagy = 0.3*im(:,:,1) + 0.6*im(:,:,2) + 0.1*im(:,:,3);

The result is that lenagy consists of a 2-D array, which can be saved to a file using for example

save lenagy.org lenagy
Zeus
  • 1,401
  • 16
  • 27