Let me demonstrate this with an example. Let's call each row of the 640 x 240 array a "scanline", and let's say that you want to take each even-numbered element of each scanline and combine it mathematically with the odd-numbered element that follows it. Thus, element 0 and element 1 on any given scanline will combine to produce some single value that will be element 0 in the 320 element result scanline, elements 2 and 3 will produce element 1 in the result scanline, 4 and 5 will produce element 3 in the result scanline, etc. Let us pretend that the input array is a byte array, that the operation will be multiply even-numbered byte by 256 and add to it its odd-numbered neighbor. The output array would then be a short integer array.
The way, then, to produce the output array without having to resort to loops is to copy out of the original array to one new array all the values that are in even-numbered subscripts, copy to another new array all the values that are in odd-numbered subscripts. You will then end up with two arrays with the same dimension that can be easily mathematically combined in one line of code. IDL has an easy way to do this even-numbered and odd-numbered subscript copying. Here is the example that demonstrates the syntax:
origArr = bindgen(640, 240) ; Keeps sequentially wrapping values 0B to 255B
; convert to short int for subsequent math operation
evenSubscriptArr = fix(origArr[0:638:2, *])
oddSubscriptArr = fix(origArr[1:639:2, *])
resultArr = (evenSubscriptArr * 256) + oddSubscriptArr
That should be all you need to produce a 16-bit 320 x 240 result array that uses all the elements of your original array as you wanted.
James Jones
|