[Image-SIG] Help wanted: sensible way to scale 16-bit grayscale image

Russell E. Owen rowen at cesmail.net
Wed Dec 15 20:17:11 CET 2004


I'm building a simple image viewer for astronomical images (after giving 
up integrating ds9 into my app). It is basically working, but I suspect 
I am not being very sensible in the way I do intensity scaling (to map a 
high dynamic range image into 8 bits).

The data arrives as 16-bit integer, though it is convenient to convert 
it to 32-bit floating point when applying scaling functions.

I had hoped to use an LUT to directly map a 32-bit floating point image 
(or 16 bit integer) to 8 bit color or grayscale (for now grayscale is 
fine, though I hope to support psuedocolor at some point). I could then 
recompute the LUT as needed (e.g. if the user asked for a different 
scaling function or contrast or...).

Unfortunately, I have not been able to figure out how to use an LUT. 
Despite the following hopeful statement in the Concepts section of the 
Handbook:

  The mode of an image defines the type and depth of a pixel
   in the image. The current release supports the following
  standard modes:
  ...
  * P (8-bit pixels, mapped to any other mode using a colour palette)

it appears that palettes can only be attached to L or P images. I hope 
I'm missing something obvious in the use of palettes.

Meanwhile, what I'm doing is:

- input data is a numarray array
- apply a scaling function to produce scaledArr,
   a 32-bit floating numarray array
- create an Image copy of scaledArr:
   self.scaledIm = Image.frombuffer("F",
       dataShapeXY, self.scaledArr.tostring())
- resize scaledIm according to the desired zoom factor
- create currIm: a 0-255 value version of scaledIm:
   currIm = self.scaledIm.point(self._dispFromScaled)
- self.tkIm = ImageTk.PhotoImage(currIm)
- display self.tkIm on a canvas

Is there a better way to handle the scaling? This seems to have adequate 
performance, but it seems messy compared to using the scaling function 
to compute an LUT which maps unscaled pixel values to an 8-bit 
displayable image.

Also, any suggestions for zoom? The main flaw in my image viewer is slow 
draw time when zoom >= 4. I fear I'll have to try to create a copy of 
only a portion of the image of interest, but that will really complicate 
panning (not to mention figuring out the coordinates of the current 
point).

-- Russell

P.S. the image viewer is part of the RO package
<http://rowen.astro.washington.edu/rowen>.
The current release has a working preliminary version as 
RO.Wdg.GrayImageDispWdg.



More information about the Image-SIG mailing list