[Image-SIG] Example Code for Displaying Pictures--I'm Stumped

Christopher Barker Chris.Barker at noaa.gov
Wed Nov 25 22:57:04 CET 2009

Wayne Watson wrote:
> I didn't know I could post, attach I guess, here. I'll do that later.

  as long as it's a small file -- it can be much easier to help

> There is one puzzling format difficulty I have with the file that 
> requires some attention. I hope to have that cleared up in the next hour 
> or two. Actually, there's a twist in the format that should be 
> mentioned. The first image (frame) is 640x480, and I'm pretty sure one 
> byte per pixel. However, every other image (frame) after that is 128 
> pixels square. An auxiliary text file provides where, x and y pixel 
> position, the small image should be pasted to form a complete image with 
> the 640x480 frame.

Maybe it's because I"m more familiar with numpy than PIL, but this is 
how I'd do that (untested, of course...):

import numpy as np

infile = file('filename')

img = np.fromfile(infile, count=640*480, dtype=np.uint8)

for i in range(num_images):
     small_image = np.fromfile(infile, count=128*128, dtype=np.uint8)
     img[x:x+128, y:y+128] = small_image

NOTE: np.histogram2d might do what you want for the histogram

I'm sure you can do somethign similar directly with PIL.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Image-SIG mailing list