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

Russell E. Owen rowen at cesmail.net
Thu Dec 16 23:27:19 CET 2004

In article <41C1D38A.90902 at hotpop.com>, Ray Pasco <pascor at hotpop.com> 

> I believe the response to Russell's question missed the point.  I 
> believe he wants to change the
> dynamic range of his images, not produce an image file of a smaller 
> size, which is the primary
> goal of producing a paletted (indexed or gray "L"evel) image....

Exactly. My image viewer offers log, sqrt and a few other scaling 
functions which the user may switch between in order to bring out 
different features of interest in the original image.

When a scaling function is selected, an appropriate 8-bit image is 
created from the original data (which is always retained unchanged) and 

Right now I am using brute force to create the 8-bit image -- using 
numarray to apply the scaling function to each pixel to create a scaled 
version to display. I had hoped, instead, to specify the desired scaling 
as an array of 256 values that told PIM how to map values from the 
original image down to 8 bits (thus only computing my scaling function 
at 256 points instead of for every pixel in the original image).

It sounds as if PIM does not have LUT support in that sense, which is a 
pity as it seems a natural thing to do.

> So, Russel, I think this is what you want to do:
> 1) Create a palette of 256 8-bit integer indices.  This is not a LUT 
> used as a transform tool.
> 2) Lets say your image consists of unsigned 16-bit values.  Decide the 
> ranges of values that will be mapped.
> E.g., let the range 0-255 map to the new image pallette value of 0, the 
> original range of 256 .. 511 ==> 1, etc.
> In other words, the original value range of [0..255, 256..511, ...]  
> will transform to the gray level values
> of [0, 1, ...]...
> 3) Create a brand new L type image.  Install your new pallette into it. 
>  Examine at each pixel of the original image
> and map its 16-bit value to a (unique) pallette value.  Write that 
> pallete value to the pixel value of the new image.
> You are now done converting the old image to a new L image.  Store,  
> display or even convert to a new image
> type as desired.

I'm not sure I get this yet.

I think you are suggesting I start by creating a table that specifies 
how values from the original image are mapped to 8-bit grayscale image, 
e.g. (using your linear example): [0, 256, 512, ...] means display 
values 0-255 as 0, 256-511 as 1, etc.

But then I don't see how to apply it. You suggest:
>Examine at each pixel of the original image and map its 16-bit value to 
a (unique) pallette value. Write that pallete value to the pixel value 
of the new image.
but is there some efficient way to do this? I suspect a normal python 
loop would be dreadfully slow.

Also, I confess I'm puzzled why you also suggest creating a palette and 
attaching it to the "L" image (maybe this is the heart of what I'm 
missing). I would think that once I had used the table to compute the 
pixel values for the 8-bit "L" image, I'd be done -- and that the proper 
palette for "L" would then be the default palette.

I hope I'm not being too dense.


-- Russell

More information about the Image-SIG mailing list