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 #36802 is a reply to message #36755] Fri, 24 October 2003 08:34 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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

How does this "work like a charm"?

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[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: Sun Oct 12 09:55:49 PDT 2025

Total time taken to generate the page: 0.64368 seconds