convert read_bpm(file, R, G, B) to N x M x 3 array? [message #52777] |
Wed, 28 February 2007 09:24 |
Mike[2]
Messages: 99 Registered: December 2005
|
Member |
|
|
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:
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?
Mike
|
|
|