Re: Getting image data - how?
- To: mathgroup at smc.vnet.net
- Subject: [mg7846] Re: [mg7781] Getting image data - how?
- From: seanross at worldnet.att.net
- Date: Mon, 14 Jul 1997 03:01:24 -0400
- Sender: owner-wri-mathgroup at wolfram.com
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"," "}, RecordSeparators->{"\n"}] 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 data. goodstuff= Partition[ Map[RGBColor,Partition[ToExpression[Take[try2,10-Length[try2]]],3]],16] 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: Show[Graphics[ RasterArray[ Partition[ MapThread[RGBColor, Transpose[ Partition[ToExpression[Take[try2,10-Length[try2]]]/256,3]]],16]]], AspectRatio->Automatic]