comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Converting 24 bit images to 8 bit images with a specific colour table
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Converting 24 bit images to 8 bit images with a specific colour table [message #15260] Thu, 06 May 1999 00:00
philaldis is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Converting 24 bit images to 8 bit images with a specific colour table
Next Topic: Re: Frame Rate With Xinteranimate

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:42:59 PDT 2025

Total time taken to generate the page: 0.00544 seconds