SCIFIO: saving Img throws java.lang.UnsupportedOperationException

Hi All,

I’m at my wits’ end trying to resolve this issue. In the following code snippet, I’m trying to load an image, filter it, segment it, generate a distance map and then save both the thresholded image and the distance map.

File file = new File(pathToFile);

SCIFIOConfig config = new SCIFIOConfig();
config.imgOpenerSetImgModes(SCIFIOConfig.ImgMode.CELL);
Img<UnsignedShortType> img = (Img<UnsignedShortType>) new ImgOpener().openImgs(file.getAbsolutePath(), config).get(0).getImg();

RandomAccessibleInterval<UnsignedShortType> channel = Views.hyperSlice(img, 2, 3);

Img<UnsignedShortType> filtered = (new DiskCachedCellImgFactory<>(new UnsignedShortType())).create(channel);

Gauss3.gauss(2.0, Views.extendValue(channel, img.firstElement().createVariable()), filtered);

OpService opService = new ImageJ().op();

Img<BitType> binary = (new DiskCachedCellImgFactory<>(new BitType())).create(filtered);
opService.threshold().huang(binary, filtered);

Img<UnsignedByteType> convertedBinary = (new DiskCachedCellImgFactory<>(new UnsignedByteType())).create(filtered);
opService.convert().uint8(convertedBinary, binary);

Img<UnsignedShortType> distanceTransform = (new DiskCachedCellImgFactory<>(new UnsignedShortType())).create(binary);
DistanceTransform.binaryTransform(binary, distanceTransform, DistanceTransform.DISTANCE_TYPE.EUCLIDIAN);

ImgSaver saver = new ImgSaver();
config.writerSetCompression("LZW");

saver.saveImg("E:/distanceMap.ome.btf", distanceTransform, config);
saver.saveImg("E:/thresholded.ome.btf", convertedBinary, config);

When I run this on my (Windows) desktop, this works absolutely fine.

However, when I try to run it on our (Linux) cluster, on exactly the same input image, I can only save the distance map - trying to save the binary image (last line), throws the following exception:

java.lang.UnsupportedOperationException: Attempting to read or write from a io.scif.io.VirtualHandle. There is no source to operate on.

I’ve tried to implement the code in various different ways, but the outcome is always the same.

Anyone have any idea how I can work around this? Anything that allows me to save the binary image resulting from the thresholding is all I am looking for.

Thanks!

This sounds like it could be a version skew issue. What are the respective versions of scifio you’re using on these two systems?

Would you mind posting the entire stack trace of the exception? It might help distinguishing this issue from others that might or might not be related:

Hi @imagejan,

Full stack trace is as follows:

Exception in thread "main" java.lang.UnsupportedOperationException: Attempting to read or write from a io.scif.io.VirtualHandle. There is no source to operate on.
	at io.scif.io.VirtualHandle.writeByte(VirtualHandle.java:226)
	at io.scif.io.RandomAccessOutputStream.writeByte(RandomAccessOutputStream.java:165)
	at io.scif.formats.tiff.TiffSaver.writeHeader(TiffSaver.java:197)
	at io.scif.formats.TIFFFormat$Writer.initialize(TIFFFormat.java:1461)
	at io.scif.AbstractWriter.savePlane(AbstractWriter.java:168)
	at io.scif.AbstractWriter.savePlane(AbstractWriter.java:160)
	at io.scif.img.ImgSaver.writePlanes(ImgSaver.java:684)
	at io.scif.img.ImgSaver.writeImg(ImgSaver.java:542)
	at io.scif.img.ImgSaver.writeImg(ImgSaver.java:528)
	at io.scif.img.ImgSaver.writeImg(ImgSaver.java:497)
	at io.scif.img.ImgSaver.writeImg(ImgSaver.java:459)
	at io.scif.img.ImgSaver.saveImg(ImgSaver.java:174)
	at io.scif.img.ImgSaver.saveImg(ImgSaver.java:158)

I don’t think different versions is the issue. I’m copying the dependencies from the Java build onto the server, so the versions of all dependencies should be exactly the same. I’m building with pom-scijava version 28, so that gives me scifio version 0.37.3.

The Java versions are also the same (1.8.0_202).