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

Home » Public Forums » archive » Re: Converting 8-bit image + pallete to 24 bit image with alpha channel
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: Converting 8-bit image + pallete to 24 bit image with alpha channel [message #19304] Fri, 10 March 2000 00:00
Struan Gray is currently offline  Struan Gray
Messages: 178
Registered: December 1995
Senior Member
Ricardo Fonseca, zamb@physics.ucla.edu writes:

> AlphaImage = BytArr(4, s[1], s[2])
> AlphaImage[0,*,*] = rr(Data[*,*])
> AlphaImage[1,*,*] = gg(Data[*,*])
> AlphaImage[2,*,*] = bb(Data[*,*])
> AlphaImage[3,*,*] = 128


It is often faster to construct the array directly than to
construct and empty array and fill the planes:

TVLCT, rr, gg, bb, /get
data = bytscl(dist(200))
s = Size(Data)

alphachannel = make_array(size=s, value=128b)
AlphaImage2 = [rr(Data), gg(Data), bb(Data), alphachannel]
alphaimage2 = reform(alphaimage2, s[1], 4, s[2], /overwrite)
alphaimage2 = transpose(alphaimage2, [1,0,2])


It is not as easy to see what is going on here, but on my machines
it is three to four times faster.

The last transpose step is necessary because of the way IDL orders
array elements in memory (as is the order of the dimensions in the
reform line). With 3-channel images you can usually avoid the
transpose step if you correctly use the TRUE or INTERLEAVE
keyword/properties of plotting routines or image objects. I haven't
used alpha channels much, and the help files are opaque, so I don't
know if you can set an interleave for a four channel image - if you
can, the transpose step can be omitted here too.


Struan
Re: Converting 8-bit image + pallete to 24 bit image with alpha channel [message #19308 is a reply to message #19304] Thu, 09 March 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Ricardo Fonseca (zamb@physics.ucla.edu) writes:

> I'm trying to convert an 8-bit grayscale image to a 24 bit image with an
> alpha channel, mapping the colors of the 8-bit image through a palette.
> Right now I'm doing it like this:
>
> CT = 23
> LoadCT,CT
> TVLCT, rr, gg, bb, /get
>
> Data = BytScl(Abs(Data), MAX = max, MIN = min)
> s = Size(Data)
> AlphaImage = BytArr(4, s[1], s[2])
> AlphaImage[0,*,*] = rr(Data[*,*])
> AlphaImage[1,*,*] = gg(Data[*,*])
> AlphaImage[2,*,*] = bb(Data[*,*])
> AlphaImage[3,*,*] = 128
>
> Which works, but I was wondering if there was a more efficient way of doing
> this. Can anyone help?

That's about the size of it, I'm afraid. :-(

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL and Linux on dual processor
Next Topic: Corruption of string variable in IDL V5.3

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

Current Time: Wed Oct 08 15:16:18 PDT 2025

Total time taken to generate the page: 0.00607 seconds