Login  Register

Re: Reading a binary file

Posted by Albert Cardona on Jun 02, 2009; 1:46pm
URL: http://imagej.273.s1.nabble.com/Reading-a-binary-file-tp3692318p3692320.html

Kb Pru wrote:
>   pixels[offset+col]=swapshort(input.readShort());
>  


Reading pixel-by-pixel may take forever unless you use a buffered input
stream.


> 2. I would like to scale the pixel value linearly. However when I change one
> line line from the above snipped to :
> pixels[offset+col]=swapshort(input.readShort()-16383);
> I get an error message "Incompatible type for method. Explicit cast needed
> to convert int to short.". How do I operate on pixel element values.
>  


In java, arithmetic operations go up to int or to double. In your case
to int.
So cast the result back to short:

pixels[offset+col]= swapshort(  (short) (input.readShort()-16383) );


Overall, you may be better off using LOCI Bioformats, which you may extend
for your particular file format and which have virtual stack (read:
dynamic loading)
capabilities.

Albert

--
Albert Cardona
http://albert.rierol.net