[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Interleaving separate arrays..
Hmm, this talk about the interleaving of Leon Majewski's data reminded
me of a question that Ricardo Fonseca had quite a while ago.. It was
about converting an 8-bit image into a 24-bit image plus an alpha
channel, interleaving the colors in the first dimension.
Struan Gray suggested using the
[red(image),green(image),blue(image),alphachan] method, then reform &
transpose. (He also pointed out that this was often not necessary,
though, since the INTERLEAVE/TRUE keywords can be used in many cases
to indicate which dimension is interleaved)
I wrote a reply to this, but as I've recently learned, it never made
it outside Goddard Space Flight Center.. Now, here a short summary,
sent from my old account in Oslo..:
There are constructs in IDL to concatenate arrays by expanding the
first dimension, expanding the second dimension etc.. as well as
adding a dimension at the "end" (using more and more [] brackets in
the array concatenation statements, respectively), but no syntactic
construct to interleave pixels in a new dimension *before* the
existing ones...
Re-shoveling arrays after building them is not my preferred mode of
operation, because of the inherent performance hit. Better to do it
right in the first place - but how to avoid loops? Is a DLM the
answer? Well, so I thought, until it dawned on me (5 minutes ago) that
Ricardo's original problem can be solved like this:
s = size(image)
image = reform(image,1,s[1],s[2],/overwrite)
alphachan = replicate(128b,1,s[1],s[2])
alphaimage = [red[image],green[image],blue[image],alphachan]
Presto.. Though I shrink in my chair admitting that I actually wrote a
DLM to do this (as in result = interleave(a,b,c,d,e,f,.....)). It
didn't take much time, though, and I did it to test my sanity after
keeping away from IDL for too long.. Guess I only came halfway through
the test :-)
My only consolation is that nobody else got it...
Stein Vidar