Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Negative-values-in-binary-byte-arrary-viewed-in-Netbeans-tp5016033p5016037.html
Hi Neil,
when you access the pixels array of a ByteProcessor, you have to apply a
mask 0xff=255 to get the pixel value:
int value = pixels[x+y*width]&0xff;
That's because the ImageJ ByteProcessor assumes unsigned values 0-255 as
usual in image processing, but the Java type 'byte' is signed, with a
range -128...+127.
It's the same for a ShortProcessor, there you have to use a mask of 0xffff.
Michael
____________________________________________________________
On Thu, March 31, 2016 03:38, nellypledge wrote:
> Hi,
> I'm debugging a plugin and I see that the values of the byte array of an
> ImageProcessor (using both get() and getPixels()) are 0's and -1's... I
> think the -1's are the true values (what are 255 in the image when you
> mouse-over), but haven't gone to lengths to figure that out.
>
> When I assign a value of 255 to the image during the code it behaves as it
> should, and I'm curious to know the reason for the -1's?
>
> Using get() and put() works well, but when I getPixels() and edit the
> values
> in that referenced array it does appear to change, and wondered if there
> are
> subtleties between the two and if the -1's are related.
>
> Thanks in advance for your time.
> Neil
>
>
>
> --
> View this message in context:
>
http://imagej.1557.x6.nabble.com/Negative-values-in-binary-byte-arrary-viewed-in-Netbeans-tp5016033.html> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html