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

Home » Public Forums » archive » Re: about color 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
Re: about color table [message #66874] Fri, 19 June 2009 07:18 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeremy Bailin writes:

> Another way of going from array to scaledData (i.e. everything in
> between TVLCT and TVImage in David's code), that's probably easier to
> deal with if you want to change the values (or number) of the cutoffs,
> is:
>
> cutoffs = [0.2, 0.3, 0.5, 0.8]
> scaledData = byte(value_locate(cutoffs, array) + 2)

Thanks, Jeremy, for pointing this out. Even as jaded an IDL
programmer has me had raised eyebrows when I read this. :-)

I've written an article about this so others can learn about it.

http://www.dfanning.com/code_tips/partition.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: about color table [message #66879 is a reply to message #66874] Thu, 18 June 2009 21:39 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeremy Bailin writes:

> Another way of going from array to scaledData (i.e. everything in
> between TVLCT and TVImage in David's code), that's probably easier to
> deal with if you want to change the values (or number) of the cutoffs,
> is:
>
> cutoffs = [0.2, 0.3, 0.5, 0.8]
> scaledData = byte(value_locate(cutoffs, array) + 2)

Oh, my goodness! Now try to explain it to him. ;-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: about color table [message #66880 is a reply to message #66879] Thu, 18 June 2009 21:30 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Jun 18, 6:01 pm, David Fanning <n...@dfanning.com> wrote:
> Hu writes:
>> I want to do something like this: I got an 2-D array with values range
>> from 0.0 to 1.0. and I want to display the array using different
>> colors. for example, if the value is greater than 0.8, the elements
>> will be displayed as red, if the values is between 0.5 and 0.8, the
>> color will be blue, and the relationship can be listed as follows:
>
>>> 0.8        red
>> 0.5-0.8   blue
>> 0.3-0.5   yellow
>> 0.2-0.3   green
>> <0.2        white
>
>> I know I need to set up a color table, and the book 'IDL Programming
>> techniques' demostrate how to set up a color table, and I set up the
>> table including those above colors.
>
>> The question is , How can I set up the relationship between the color
>> table and the different ranges? I mean how to 'tell' the computer
>> display the array using this relationship?
>
>    TVLCT, FSC_Color(['white','green','yellow','blue','red'], /TRIPLE), 1
>    s = Size(array, /DIMENSIONS)
>    scaledData = BytArr(s[0], s[1])
>    I = Where(array LT 0.2, count)
>    IF count GT 0 THEN scaledData[I] = 1
>    I = Where(array GE 0.2 AND array LT 0.3, count)
>    IF count GT 0 THEN scaledData[I] = 2
>    I = Where(array GE 0.3 AND array LT 0.5, count)
>    IF count GT 0 THEN scaledData[I] = 3
>    I = Where(array GE 0.5 AND array LT 0.8, count)
>    IF count GT 0 THEN scaledData[I] = 4
>    I = Where(array GT 0.8, count)
>    IF count GT 0 THEN scaledData[I] = 5
>    TVImage, scaledData, /KEEP, /NOINTERP
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Another way of going from array to scaledData (i.e. everything in
between TVLCT and TVImage in David's code), that's probably easier to
deal with if you want to change the values (or number) of the cutoffs,
is:

cutoffs = [0.2, 0.3, 0.5, 0.8]
scaledData = byte(value_locate(cutoffs, array) + 2)

-Jeremy.
Re: about color table [message #66882 is a reply to message #66880] Thu, 18 June 2009 21:12 Go to previous messageGo to next message
Hu is currently offline  Hu
Messages: 35
Registered: January 2009
Member
On Jun 18, 6:01 pm, David Fanning <n...@dfanning.com> wrote:
> Hu writes:
>> I want to do something like this: I got an 2-D array with values range
>> from 0.0 to 1.0. and I want to display the array using different
>> colors. for example, if the value is greater than 0.8, the elements
>> will be displayed as red, if the values is between 0.5 and 0.8, the
>> color will be blue, and the relationship can be listed as follows:
>
>>> 0.8        red
>> 0.5-0.8   blue
>> 0.3-0.5   yellow
>> 0.2-0.3   green
>> <0.2        white
>
>> I know I need to set up a color table, and the book 'IDL Programming
>> techniques' demostrate how to set up a color table, and I set up the
>> table including those above colors.
>
>> The question is , How can I set up the relationship between the color
>> table and the different ranges? I mean how to 'tell' the computer
>> display the array using this relationship?
>
>    TVLCT, FSC_Color(['white','green','yellow','blue','red'], /TRIPLE), 1
>    s = Size(array, /DIMENSIONS)
>    scaledData = BytArr(s[0], s[1])
>    I = Where(array LT 0.2, count)
>    IF count GT 0 THEN scaledData[I] = 1
>    I = Where(array GE 0.2 AND array LT 0.3, count)
>    IF count GT 0 THEN scaledData[I] = 2
>    I = Where(array GE 0.3 AND array LT 0.5, count)
>    IF count GT 0 THEN scaledData[I] = 3
>    I = Where(array GE 0.5 AND array LT 0.8, count)
>    IF count GT 0 THEN scaledData[I] = 4
>    I = Where(array GT 0.8, count)
>    IF count GT 0 THEN scaledData[I] = 5
>    TVImage, scaledData, /KEEP, /NOINTERP
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Great, Thanks David
Re: about color table [message #66903 is a reply to message #66882] Thu, 18 June 2009 15:01 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Hu writes:

> I want to do something like this: I got an 2-D array with values range
> from 0.0 to 1.0. and I want to display the array using different
> colors. for example, if the value is greater than 0.8, the elements
> will be displayed as red, if the values is between 0.5 and 0.8, the
> color will be blue, and the relationship can be listed as follows:
>
>> 0.8 red
> 0.5-0.8 blue
> 0.3-0.5 yellow
> 0.2-0.3 green
> <0.2 white
>
> I know I need to set up a color table, and the book 'IDL Programming
> techniques' demostrate how to set up a color table, and I set up the
> table including those above colors.
>
> The question is , How can I set up the relationship between the color
> table and the different ranges? I mean how to 'tell' the computer
> display the array using this relationship?

TVLCT, FSC_Color(['white','green','yellow','blue','red'], /TRIPLE), 1
s = Size(array, /DIMENSIONS)
scaledData = BytArr(s[0], s[1])
I = Where(array LT 0.2, count)
IF count GT 0 THEN scaledData[I] = 1
I = Where(array GE 0.2 AND array LT 0.3, count)
IF count GT 0 THEN scaledData[I] = 2
I = Where(array GE 0.3 AND array LT 0.5, count)
IF count GT 0 THEN scaledData[I] = 3
I = Where(array GE 0.5 AND array LT 0.8, count)
IF count GT 0 THEN scaledData[I] = 4
I = Where(array GT 0.8, count)
IF count GT 0 THEN scaledData[I] = 5
TVImage, scaledData, /KEEP, /NOINTERP

Cheers,

David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: about color table [message #67120 is a reply to message #66874] Fri, 19 June 2009 20:55 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Jun 19, 10:18 am, David Fanning <n...@dfanning.com> wrote:
> Jeremy Bailin writes:
>> Another way of going from array to scaledData (i.e. everything in
>> between TVLCT and TVImage in David's code), that's probably easier to
>> deal with if you want to change the values (or number) of the cutoffs,
>> is:
>
>> cutoffs = [0.2, 0.3, 0.5, 0.8]
>> scaledData = byte(value_locate(cutoffs, array) + 2)
>
> Thanks, Jeremy, for pointing this out. Even as jaded an IDL
> programmer has me had raised eyebrows when I read this. :-)
>
> I've written an article about this so others can learn about it.
>
>   http://www.dfanning.com/code_tips/partition.html
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Yeah, value_locate is very handy for problems like this! I
particularly like using it as a precursor to histogram - i.e. if you
want to do something fancy using reverse_indices but don't have
uniformly-spaced bins, first use value_locate to get integer indices
and then use histogram to do the heavy lifting.

-Jeremy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Using t3d to perform a reflection
Next Topic: about color table

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

Current Time: Wed Oct 08 15:17:35 PDT 2025

Total time taken to generate the page: 0.00604 seconds