Re: How to read 'raw' data as 32 bit unsigned in Java

Posted by Kenneth Sloan-2 on
URL: http://imagej.273.s1.nabble.com/How-to-read-raw-data-as-32-bit-unsigned-in-Java-tp5021772p5021779.html

Ah...if the data are really 16-bit, then my recommendation is to
import the image as a 32-bit float, apply Brightness/Contrast,
and use an OVERLAY to highlight the problem pixels.

But, if you really want RGB, import as 32-bit, adjust,
and use Image->Type->RGB and you are done.

Note that this loses precision (but, you can't see much more than
8-bits on the screen anyway).

You also lose access to the actual original pixel values - but
perhaps that's not important.

I do this routinely with data that claim to be 32-bit floats in the
range [0.0..1.0).  These are essentially 24-bit unsigned integers.

It looks like there is no reason for you to import a byte array
and twiddle bits to construct ints.  Fiji will happily import
the image as 32-bit float, adjust brightness/contrast, and convert
to RGB (if that's what you want).

Is your code to find and highlight problem pixels written as a
Fiji plugin, or as a stand-alone Java program?


--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Feb 12, 2019, at 14:48, Robert Lockwood <[hidden email]> wrote:
>
> When I look at the imported images in Fiji I apply Brightness/Contrast with
> auto for a decent image.
>
> If I can do the same thing in Java and then convert to RGB I can then
> manipulate the pixels I've identified by my comparison code.
>
> BTW the values in my 32 bit first came from the camera as defined as C
> unsigned shorts so all the values are less than 64K so I can extract the
> Java short values easily.
>
> On Tue, Feb 12, 2019 at 11:20 AM Kenneth Sloan <[hidden email]>
> wrote:
>
>> If you do this in Java, I think there are a couple of workarounds.
>>
>> Here's one idea: Since you already can "process these data as ints", you
>> should be able to create your own 8-bit RGB image.  Of course, you only
>> get 8-bits of gray scale.
>>
>> Here's another idea: you should be able to import the image as a 32-bit
>> float image.  If there is non-zero data in the upper 8 bits, the image
>> will look
>> very strange, but at least you'll have a 32-bit array.  Next, take each
>> 32-bit float pixel value and use Float.floatToRawIntBits to get
>> your 32-bit integer values.
>>
>> Since you can already create the int values from your byte array, I would
>> start
>> with that idea.
>>
>> Be careful about signed/unsigned.
>>
>> Finally, I would consider creating a 24-bit integer gray-scale value, and
>> using
>> that as a 32-bit float (using Float.intBitsToFloat).  This gives you a
>> float image
>> where the values are between 0.0 and 1.0.  You can then use an Overlay to
>> highlight
>> the problem pixels.  Use either idea above to get a 32-bit unsigned value,
>> and
>> scale it to 24-bits.  Convert that to a float, and store it in a 32-bit
>> float image.
>>
>> Or, simply create a 16-bit integer gray scale image, and use an Overlay.
>>
>> Your choice may depend on what you know about the range of values.  The
>> advantage of
>> my 24-bit version above is that you have a bit more flexibility in
>> dynamically adjusting
>> the range of displayed gray levels.  The disadvantage is that the numbers
>> will all
>> be presented as (0.0..1.0) instead of [0..65535] (for the 16-bit version)
>>
>> --
>> Kenneth Sloan
>> [hidden email]
>> Vision is the art of seeing what is invisible to others.
>>
>>
>>
>>
>>
>>> On Feb 12, 2019, at 12:37, Herbie <[hidden email]> wrote:
>>>
>>> Good day,
>>>
>>> ImageJ doesn't support 32 bit integer gray scale images.
>>>
>>> Supported are 8bit and 16bit integer as well as 32bit float. Furthermore
>> 24bit (3 X 8bit) RGB and index color 8bit.
>>>
>>> Regards
>>>
>>> Herbie
>>>
>>> :::::::::::::::::::::::::::::::::::::::::::::
>>> Am 12.02.19 um 19:15 schrieb Robert Lockwood:
>>>> Working with Java I have raw data files with 32 bit integer gray scale
>> data
>>>> which I read into a byte[] array.  I process these data as ints looking
>> for
>>>> adjacent pixels that have the same value in order to debug a problem
>> with
>>>> the camera.
>>>> I'd like to create a scaled grayscale RGB from the original data so
>> that I
>>>> may color the detected adjacent pixels to allow us to detect patterns
>>>> visually but I don't understand how to create and populate a grayscale
>>>> integer ImageJ array and have not found an example by Google searching.
>>>> How do I do this?
>>>> TIA
>>>> --
>>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html