[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 10 bit packed as 8 bit unpacking



This worked beautifully "right out of the box".
Thanks,

Dave.

In article <onpuc07be3.fsf@cow.physics.wisc.edu>, Craig Markwardt <craigmnet@cow.physics.wisc.edu> writes:
>
>dmarshall@ivory.trentu.ca writes:
>
>> I would like to get the raw information from a 1280 by 960 image that has 
>> 10 bit resolution. I can get at a dumped version that comes out in 8 bit 
>> chunks.
>> 
>> Could I read the image into a bytarr and "simply" reformat it as 10 bit?
>
>This question comes up now and then.  I think the answer, "simply," is
>sort of.  You will probably use the ISHFT function to shift bits into
>place.  However, IDL does not have a 10-bit data type, so you will
>have to load it into a 16-bit INT or UINT.
>
>However, I do have a suggestion that might help: remember that every
>group of five bytes contains four data values.  Thus, for speed, you
>can reformat the original array into quintuples of bytes, and then
>read out the interleaved array values with appropriate choices if
>ISHFT and bitwise AND.
>
>n = 1280L & m = 960L
>rawimg = bytarr(n*m*5/4)              ;; 10-bit is 20% more than 8-bit
>readdatafromdisk, rawimg              ;; Read data however you do it
>
>rawimg = reform(rawimg, 5, n*m/4)     ;; Reform into quintuples
>outimg = intarr(4, n*m/4)             ;; Make new output image of quadruples
>ii = lindgen(n*m/4)                   ;; Indices for interleaved access
>
>;; Interleave the bytes together
>outimg(0,ii) = ishft(rawimg(0,jj) AND 'ff'x,2) + ishft(rawimg(1,jj) AND 'c0'x,-6)
>outimg(1,ii) = ishft(rawimg(1,jj) AND '3f'x,4) + ishft(rawimg(2,jj) AND 'f0'x,-4)
>outimg(2,ii) = ishft(rawimg(2,jj) AND '0f'x,6) + ishft(rawimg(3,jj) AND 'fc'x,-2)
>outimg(3,ii) = ishft(rawimg(3,jj) AND '03'x,8) + ishft(rawimg(4,jj) AND 'ff'x, 0)
>
>outimg = reform(outimg, n, m)         ;; Convert back to an NxM array
>
>This will require some tweaking, but it is probably the best way to
>go.  Check it out at least.  The final result will be a 16-bit 2-d
>array suitable for manipulation in IDL.
>
>Craig
>
>-- 
>--------------------------------------------------------------------------
>Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
>Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
>--------------------------------------------------------------------------