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 #52770 is a reply to message #52759] Thu, 01 March 2007 01:04 Go to previous messageGo to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On 28 Feb 2007 09:24:38 -0800, "Mike" <Michael.Miller5@gmail.com>
wrote:

> Dear IDL gang,
>
> 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:

You know you could do this right?
button=widget_button(base,value=filename,/bitmap)

> 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?

Why not just using this:
result=read_bmp(filename)
This will give a 3xNxM, so you can use this to get NxMx3:
result=transpose(result,[1,2,0])
[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: Thu Oct 16 18:05:34 PDT 2025

Total time taken to generate the page: 0.47818 seconds