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 |
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 |
Thanks Michael for those crucial details.
Could I also ask if I can update the contents of the getPixels byte array reference by simply assigning values to the reference? I've always struggled with java 'pointers'.
Thanks
Neil
From: "Michael Schmid-3 [via ImageJ]" <ml-node+[hidden email]>
Sent: Mar 31, 2016 11:50 AM To: Anthony, Neil Subject: Re: Negative values in binary byte arrary viewed in Netbeans 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 If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/Negative-values-in-binary-byte-arrary-viewed-in-Netbeans-tp5016033p5016037.html
This e-mail message (including any attachments) is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message (including any attachments) is strictly prohibited. If you have received this message in error, please contact the sender by reply e-mail message and destroy all copies of the original message (including attachments). |
Hi Neil,
yes, you can modify the byte values in the pixels array. This is best done in a PlugInFilter. This will provide all the necessary infrastructure such as preparing for Undo, checking whether it is an 8-bit image, etc. Do the modifications in the PlugInFilter's run(ip) method. Roughly like this (I did not try, there might be mistakes in it): public class My_Multiply_Plugin implements PlugInFilter { final static int flags = DOES_8G; //only for 8-bit images public int setup(String arg, ImagePlus imp) { return IJ.setupDialog(imp, flags); //ask in case of a stack } public void run(ImageProcessor ip) { pixels = (byte[])ip.getPixels(); for (int i=0; i<pixels.length; i++) { int value = pixels[i]&0xff; value = value*2; if (value > 255) value = 255; pixels[i] = (byte)value; } } } If you want a dialog for the filter parameters and preview, use the ExtendedPlugInFilter interface. Michael __________________________________________________________________ On Thu, March 31, 2016 20:10, nellypledge wrote: > Thanks Michael for those crucial details. > > Could I also ask if I can update the contents of the getPixels byte array > reference by simply assigning values to the reference? I've always > struggled with java 'pointers'. > > Thanks > Neil > > > From: "Michael Schmid-3 [via ImageJ]" > <[hidden email]> > Sent: Mar 31, 2016 11:50 AM > To: Anthony, Neil > Subject: Re: Negative values in binary byte arrary viewed in Netbeans > > 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 > > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://imagej.1557.x6.nabble.com/Negative-values-in-binary-byte-arrary-viewed-in-Netbeans-tp5016033p5016037.html > To unsubscribe from Negative values in binary byte arrary viewed in > Netbeans, click > here< > NAML<http://imagej.1557.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > > ________________________________ > > This e-mail message (including any attachments) is for the sole use of > the intended recipient(s) and may contain confidential and privileged > information. If the reader of this message is not the intended > recipient, you are hereby notified that any dissemination, distribution > or copying of this message (including any attachments) is strictly > prohibited. > > If you have received this message in error, please contact > the sender by reply e-mail message and destroy all copies of the > original message (including attachments). > > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Negative-values-in-binary-byte-arrary-viewed-in-Netbeans-tp5016033p5016038.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 |
Thanks Michael, that sorted it. Cooking on gas now ;) Neil From: Michael Schmid-3 [via ImageJ] [mailto:ml-node+[hidden email]]
Hi Neil,
If you reply to this email, your message will be added to the discussion below: To unsubscribe from Negative values in binary byte arrary viewed in Netbeans,
click here. |
Free forum by Nabble | Edit this page |