I open a simple 8-bit single channel tif in QuPath and try to get imp and show it:
PyramidalCell-ome_Z001.tif (67.3 KB) PyramidalCell-series-_Z001.tif (66.7 KB)
img = server.readBufferedImage(request);
imp = IJTools.convertToUncalibratedImagePlus(title,img);
imp.show();
I have checked that the sampleModel.getNumBands() == 1:
aSampleModel = img.getSampleModel();
aNumBands = aSampleModel.getNumBands();
thus the code should go to the bottom one:
// Create whatever image ImageJ will give us (worked for color or 8-bit gray)
imp = new ImagePlus(title, img);
However,
For the two tif files they shows difference:
For PyramidalCell-ome_Z001.tif, which is exported as ome tiff, imp shows 8-bit normal image on screen, and QuPath print log:
11:17:00.119 [main] [INFO ] loci.formats.in.MinimalTiffReader - Reading IFDs
11:17:00.129 [main] [INFO ] loci.formats.in.MinimalTiffReader - Populating metadata
11:17:00.129 [main] [INFO ] loci.formats.in.TiffReader - Checking comment style
11:17:00.139 [main] [INFO ] loci.formats.in.BaseTiffReader - Populating OME metadata
11:17:00.209 [main] [INFO ] loci.formats.in.MinimalTiffReader - Reading IFDs
11:17:00.219 [main] [INFO ] loci.formats.in.MinimalTiffReader - Populating metadata
11:17:00.219 [main] [INFO ] loci.formats.in.TiffReader - Checking comment style
11:17:00.219 [main] [INFO ] loci.formats.in.BaseTiffReader - Populating OME metadata
but for PyramidalCell-series-_Z001.tif which is exported as adjustable tiff series, it shows black RGB image with no image content, and no log is printed out.
These two images opens with no problem in QuPath, but the results is so different:
I cannot find a way to get a corrrect imp from PyramidalCell-series-_Z001.tif,even if I use
imp = IJTools.convertToImagePlus(server__,request).getImage();
public static ImagePlus convertToUncalibratedImagePlus(String title, BufferedImage img) {
ImagePlus imp = null;
SampleModel sampleModel = img.getSampleModel();
int dataType = sampleModel.getDataType();
int w = img.getWidth();
int h = img.getHeight();
if ((dataType == DataBuffer.TYPE_BYTE && (sampleModel.getNumBands() != 1 || img.getType() == BufferedImage.TYPE_BYTE_INDEXED)) ||
dataType == DataBuffer.TYPE_USHORT || dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_FLOAT || dataType == DataBuffer.TYPE_DOUBLE) {
// Handle non-8-bit images
ImageStack stack = new ImageStack(w, h);
for (int b = 0; b < sampleModel.getNumBands(); b++) {
// Read data as float (no matter what it is)
FloatProcessor fp = new FloatProcessor(w, h);
float[] pixels = (float[])fp.getPixels();
img.getRaster().getSamples(0, 0, w, h, b, pixels);
// sampleModel.getSamples(0, 0, w, h, b, pixels, img.getRaster().getDataBuffer());
// Convert to 8 or 16-bit, if appropriate
if (dataType == DataBuffer.TYPE_BYTE) {
ByteProcessor bp = new ByteProcessor(w, h);
bp.setPixels(0, fp);
stack.addSlice(bp);
} else if (dataType == DataBuffer.TYPE_USHORT) {
ShortProcessor sp = new ShortProcessor(w, h);
sp.setPixels(0, fp);
stack.addSlice(sp);
} else
stack.addSlice(fp);
}
imp = new ImagePlus(title, stack);
} else {
// Create whatever image ImageJ will give us (worked for color or 8-bit gray)
imp = new ImagePlus(title, img);
}
return imp;
}