comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: 10 bit packed as 8 bit unpacking
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: 10 bit packed as 8 bit unpacking [message #25503] Wed, 20 June 2001 06:37
dmarshall is currently offline  dmarshall
Messages: 23
Registered: December 1997
Junior Member
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
> ------------------------------------------------------------ --------------
Re: 10 bit packed as 8 bit unpacking [message #25508 is a reply to message #25503] Tue, 19 June 2001 08:11 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: remove routine from memory
Next Topic: 24 bit color depth confuses my color table

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 17 10:06:27 PDT 2025

Total time taken to generate the page: 2.56084 seconds