imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
17 stars 25 forks source link

Conversion ImagePlus > Dataset > ImagePlus throws UnsupportedOperationException #241

Open imagejan opened 4 years ago

imagejan commented 4 years ago

The following script:

#@ ConvertService cs

import ij.IJ
import ij.ImagePlus
import net.imagej.Dataset

imp1 = IJ.createImage("Test", "8-bit white", 100, 100, 1);

data1 = cs.convert(imp1, Dataset.class)
imp1converted = cs.convert(data1, ImagePlus.class)

throws:

java.lang.UnsupportedOperationException
    at java.util.AbstractList.set(AbstractList.java:132)
    at net.imglib2.img.planar.PlanarImg.setPlane(PlanarImg.java:256)
    at net.imglib2.img.planar.PlanarImg.setPlane(PlanarImg.java:66)
    at net.imglib2.img.display.imagej.PlanarImgToVirtualStack.setPlaneCastType(PlanarImgToVirtualStack.java:168)
    at net.imglib2.img.display.imagej.PlanarImgToVirtualStack.setPixelsZeroBasedIndex(PlanarImgToVirtualStack.java:163)
    at net.imglib2.img.display.imagej.AbstractVirtualStack.setPixels(AbstractVirtualStack.java:95)
    at ij.ImagePlus.setProcessor2(ImagePlus.java:645)
    at ij.ImagePlus.setStack(ImagePlus.java:709)
    at ij.ImagePlus.<init>(ImagePlus.java:155)
    at net.imglib2.img.display.imagej.PlanarImgToVirtualStack.wrap(PlanarImgToVirtualStack.java:115)
    at net.imagej.legacy.translate.ImagePlusCreator.createImagePlus(ImagePlusCreator.java:112)
    at net.imagej.legacy.translate.ImagePlusCreator.createLegacyImage(ImagePlusCreator.java:96)
    at net.imagej.legacy.translate.ImagePlusCreator.createLegacyImage(ImagePlusCreator.java:89)
    at net.imagej.legacy.translate.ImageTranslator.createLegacyImage(ImageTranslator.java:76)
    at net.imagej.legacy.LegacyImageMap.registerDataset(LegacyImageMap.java:234)
    at net.imagej.legacy.convert.DatasetToImagePlusConverter.convert(DatasetToImagePlusConverter.java:69)
    at org.scijava.convert.AbstractConvertService.convert(AbstractConvertService.java:128)
    at org.scijava.convert.ConvertService$convert.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at Script37.run(Script37.groovy:10)
    at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:303)
    at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$20(DefaultThreadService.java:228)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
ctrueden commented 3 years ago

I just ran into this as well, via the following Groovy script:

#@ ConvertService cs
#@ Img img
import ij.ImagePlus
imp = cs.convert(img, ImagePlus.class);
print(imp)

After opening the Blobs image (which opens natively as an ImagePlus, and is implicitly converted to Img to fill the img parameter here).

imagejan commented 3 years ago

Another way to reproduce this, with the Blobs sample image opened in the legacy UI:

#@ Dataset input
#@ UIService ui

ui.show(input)