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

Home » Public Forums » archive » Re: convert read_bpm(file, R, G, B) to N x M x 3 array?
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: convert read_bpm(file, R, G, B) to N x M x 3 array? [message #52776 is a reply to message #52770] Wed, 28 February 2007 09:45 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mike writes:

> If I read a color bitmap file like this:
>
> bmp = READ_BMP(filename, R, G, B)
>
> bmp is an N x M array with values that are indices of the
> RGB arrays. For example, if bmp[5,10] = 3, the color
> triple for that pixel is R[3], G[3], B[3]. To convert this to
> an N x M x 3 for widget_button values, I've used a brute
> force method:
>
> bmp = read_bmp(filename, R, G, B)
> s = size(bmp, /structure)
> Nx = s.dimensions[0]
> Ny = s.dimensions[1]
> Nc = n_elements(R)
> bmpR = bytarr(Nx, Ny)
> bmpG = bytarr(Nx, Ny)
> bmpB = bytarr(Nx, Ny)
> for c = 0, Nc-1 do begin
> i = where(bmp eq c, count)
> if count gt 0 then begin
> bmpR[i] = R[c]
> bmpG[i] = G[c]
> bmpB[i] = B[c]
> endif
> endfor
> result = [[[bmpR]],[[bmpG]],[[bmpB]]]
>
> It seems like there aught to be a more IDLy way do
> this, but my juggling skills are failing me. Can
> anyone suggest something that takes fewer lines of
> code and is more consistent with The IDL Way?

It seems to me something like this should work:

bmp = read_bmp(filename, R, G, B)
bmp24 = [[r[bmp]], [g[bmp]], [b[bmp]]]

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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: personal license problem
Next Topic: IDL Online help-- Windows-- Favorites

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

Current Time: Sat Oct 11 20:16:18 PDT 2025

Total time taken to generate the page: 1.52309 seconds