简体   繁体   中英

Image J 16 bit Signed Buffered Image

So my question is how to get 16 bit bufferedImage from ij.ImagePlus...? If am trying to get using ShortProcessor it change my signed image to unsigned so i am not getting original image...Thanks in advance can any one provide solution.

在此处输入图片说明

How ImageJ display 16 bit signed image in their viewer..and we only get 8 bit bufferedImage or 16 bit unsigned bufferedImage So how can i get 16 bit signed BufferedImage..?

ImageJ can represent a signed 16-bit type using a special Calibration function. The isSigned16Bit() method indicates when that specific calibration function is in use—it is a linear m*x+b calibration where m=1 and b=-32768; this can be seen in the ImageJ source code .

ImageJ provides a way to obtain a BufferedImage from an ImagePlus via the getImage() method. However, this always returns an 8-bit BufferedImage .

So the next approach is to create your own BufferedImage with type DataBuffer.TYPE_SHORT , which wraps the same short[] array that backs the original ImagePlus object. Unfortunately, due to ImageJ's internal representation of signed 16-bit data, the values will be off by a constant offset of 32768—eg, a raw value of -444 will be stored in ImageJ's short[] array as 32324. Due to this fact, you must manually adjust all your values before wrapping as a BufferedImage .

Here is some example code:

import io.scif.gui.AWTImageTools;
...

final ImagePlus imp =
    IJ.openImage("http://imagej.net/images/ct.dcm.zip");

// get pixels array reference
final short[] pix = (short[]) imp.getProcessor().getPixels();
final int w = imp.getWidth();
final int h = imp.getHeight();
final boolean signed = imp.getCalibration().isSigned16Bit();

if (signed) {
    // adjust raw pixel values
    for (int i=0; i<pix.length; i++) {
        pix[i] -= 32768;
    }
}

// convert to BufferedImage
final BufferedImage image = AWTImageTools.makeImage(pix, w, h, signed);

For the actual conversion of short[] to BufferedImage , this code makes use of the SCIFIO library's AWTImageTools.makeImage utility methods. SCIFIO is included with the Fiji distribution of ImageJ . Alternately, it is only a few lines of code which would be easy to copy and paste from the routine in question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM