Converting 24 bit images to 8 bit images with a specific colour table [message #15260] |
Thu, 06 May 1999 00:00 |
philaldis
Messages: 32 Registered: March 1999
|
Member |
|
|
Well, the subject says it all, really.
If I have a 24bit image and I want to convert it to an 8bit image
which uses a particular table, so find nearest values.
This is of particular use, when you're writing multiple gifs from 24
bit images, because color_quan, will obviously not work, because the
colour table has to be global.
The only way I can think to do it is very slow and certainly not using
IDL array operations. For simplicity I'll asume that the image is
interleaved true=1, i.e. 3 x n x m
FUNCTION ConvertTo8Bit, image, r, g, b, TRUE=true
colours = BytArr(3,256)
colours[0,*] = r
colours[1,*] = g
colours[2,*] = b
convertedImage = BytArr((Size(image, /DIMENSIONS))[1],(Size(image,
/DIMENSIONS))[2])
multiplier = REPLICATE(1B, 256)
FOR i=0, (Size(image, /DIMENSIONS))[1]-1 DO BEGIN
FOR j=0, (Size(image, /DIMENSIONS))[2]-1 DO BEGIN
temp = TOTAL(ABS(colours-([image[0,i,j],image[1,i,j],
image[2,i,j]]#multiplier)), 1)
temp1 = (WHERE(temp EQ Min(temp)))[0]
convertedImage[i,j] = temp1
ENDFOR
ENDFOR
RETURN, convertedImage
END
There must be a better way to do it.........
Cheers,
Phil Aldis
|
|
|