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 #36799 is a reply to message #36682] Fri, 24 October 2003 08:55 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Fri, 24 Oct 2003 08:34:06 -0700, David Fanning wrote:

> Folks,
>
> Ok, I'm confused.
>
> JD Smith wrote the other day in response to Mr. Thilmann:
>
>>> 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-om]
>> 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.
>
> To which Oliver responded with this:
>
>> Impressive :)
>> Works like a charm. Thank you!
>
> But,... it's not working like a charm for me. :-(
>
> In fact, when I run this code, I find that index_image is a LONG
> *vector*, not the 2D image I was expecting. What am I missing here?
>
> In line three:
>
> wh=where(h gt 0,cnt) # Should be fewer than 256
>
> I used:
>
> wh=where(h gt 0,cnt) # 255

Sorry, this is a Perl comment character slipping in... too much Perl'ing
for IDLWAVE lately (hidden IDLWAVE rumor of the week: an IDL6 version with
full doc support should be out early next week). It should read:

wh=where(h gt 0,cnt) ; Should be fewer than 256

That is, you'd better have fewer than 256 colors in your rgb image if
you'd like to create an exact indexed image from it. Also note that the
original r,g, & b were intended to be *images*, one for each color plane
of your 24bit image, i.e. I should have written:

rgb_image=r_image+256L*(g_image+256L*b_image)

Got Charm?

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: Fri Oct 10 14:34:37 PDT 2025

Total time taken to generate the page: 0.88478 seconds