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

Home » Public Forums » archive » color_quan - how for exactly 256 colors?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: color_quan - how for exactly 256 colors? [message #36755 is a reply to message #36682] Fri, 17 October 2003 11:57 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Fri, 17 Oct 2003 01:01:33 -0700, Oliver Thilmann wrote:

>> David Fanning <david@dfanning.com> wrote in message
>> news:<MPG.19f86c414eaf8be5989719@news.frii.com>...
>
>> What does this mean!? By definition, there will be no "exact" results
>> when you sample 16.7 million colors down to 256. It just, uh...,
>> mathematically can't be done. :-)
>
> What I mean is: I know that my image contains not more than 256
> different RGB colors (out of 16.7 million) - I created the RGB image
> from an indexed image and now I want to transform it back. This can be
> done exactly and I wondered whether IDL provides a method to get that
> done. Cheers,

Yes, with HISTOGRAM:

rgb_image=r+256L*(g+256L*b)
h=histogram(rgb_image,OMIN=om)
wh=where(h gt 0,cnt) # Should be fewer than 256
h[wh]=bindgen(cnt)
index_image=h[rgb_image]
colors=om+wh ; these are your <=256 colors
r_vec=colors AND 255L
g_vec=ishft(colors,-8) AND 255L
b_vec=ishft(colors,-16) AND 255L
tvlct,r_vec,g_vec,b_vec
tv,index_image

Probably not the most efficient method in the universe, given the
sparseness of the histogram, but it gets the job done.

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Create a matrix using repmat
Next Topic: Re: Sorry Re: which OS is faster for idl?

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

Current Time: Sat Oct 11 07:52:37 PDT 2025

Total time taken to generate the page: 1.52102 seconds