MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Getting image data - how?

  • To: mathgroup at
  • Subject: [mg7846] Re: [mg7781] Getting image data - how?
  • From: seanross at
  • Date: Mon, 14 Jul 1997 03:01:24 -0400
  • Sender: owner-wri-mathgroup at

Allyn W. Dunstan wrote:
> Hi,
> I'm trying to read an image (I'm willing to use nearly any format - JPEG,
> GIF, TIFF, even MS BMP).  Thus far, the only one I've found useful is PPM
> (it's ASCII so I can parse out the parts I'm interested in).  I can import
> images and look at them, but that doesn't let me perform calculations on
> individual pixel values.
> Any suggestions?

I took the 'Blue Rivets.bmp' located in the windows directory(its a file
meant to be used as windows wallpaper) and loaded it into paintshop pro,
then converted it to PPM-portable pixel map format and saved it in my
root directory.  the following line reads the file in:

try2=ReadList["c:\Blue Rivets.ppm",Word,WordSeparators->{"\t"," "},

The PPM file format has a little header.  The following code removes the
header and parses the data.  Note that you could replace the 16 with an
appropriate element from the header so that it automatically parses the


which can be printed as you see fit.  If you want to just have the data
without the RGBColor directives, then modify the above line to eliminate
the Map-ing of the RGBColor onto the Partitioned data. After doing this,
though, I think that PPM format is not the best for analysis of the
pixels because it is RGB color format and you are left with having to
decide what kind of false color map to use.  I think that PGM-Portable
grey map would be better for doing fft's etc on, but I haven't written
any code to do that yet.  Also, a little while ago, someone posted their
code to read in RAW image data, which is also supported by paintshop
pro.  I think they used a similar idea to mine-using a ReadList.

PS.  If you want to be able to print the array goodstuff into a graphics
format, you need to use RasterArray:


  • Prev by Date: Re: But can it do...
  • Next by Date: Re: Question on Positive[x]=True
  • Previous by thread: Getting image data - how?
  • Next by thread: Partial Derivatives