Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImagePlus conversion leads to multiple compatible inputs being listed #230

Open
imagejan opened this issue Dec 9, 2019 · 1 comment
Open

Comments

@imagejan
Copy link
Member

imagejan commented Dec 9, 2019

Consider this Groovy script (run after opening e.g. the Blobs sample image):

#@ ObjectService os
#@ ConvertService cs

import ij.ImagePlus
import net.imagej.Dataset
import net.imagej.ImgPlus
import net.imagej.display.ImageDisplay
import ij.WindowManager

imp = WindowManager.getActiveImage()

def printAvailableObjects(type) {
	println "		$type direct:"
	os.getObjects(type).each {
		println "			--- ${it.class} $it"
	}
	
	println "		$type converted:"
	cs.getCompatibleInputs(type).each {
		println "			--- ${it.class} $it"
	}
}

println "***** Before conversion:"
printAvailableObjects(ImagePlus.class)

img = cs.convert(imp, Dataset.class)

println "***** After conversion:"
printAvailableObjects(ImagePlus.class)

null

which will output:

***** Before conversion:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
			--- class net.imagej.legacy.convert.ImageTitleToImagePlusConverter$ImageTitle blobs.gif
***** After conversion:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
			--- class net.imagej.legacy.convert.ImageTitleToImagePlusConverter$ImageTitle blobs.gif
			--- class net.imagej.DefaultDataset blobs.gif
			--- class net.imagej.display.DefaultImageDisplay [net.imagej.display.DefaultDatasetView@50305626]

Consistently, when using a script like this one:

#@ ImagePlus imp1
#@ ImagePlus imp2

... three options will be shown for each parameter, despite a single image being open (because the AbstractInputHarvester uses the same mechanism to retrieve compatible inputs).

image

@imagejan
Copy link
Member Author

imagejan commented Dec 9, 2019

With a different variation of these scripts, it can happen that a reference to a Dataset and its DefaultImageDisplay remains present even if all image windows have been closed.

To reproduce:

  1. Run this Groovy script:
#@ ObjectService os
#@ ConvertService cs
#@ OpService ops
#@ DatasetService ds
#@ UIService ui

import ij.ImagePlus
import net.imagej.Dataset
import net.imagej.ImgPlus
import net.imagej.display.ImageDisplay
import ij.WindowManager

img = ops.create().img([32, 64] as int[])

def printAvailableObjects(type) {
	println "		$type direct:"
	os.getObjects(type).each {
		println "			--- ${it.class} $it"
	}
	
	println "		$type converted:"
	cs.getCompatibleInputs(type).each {
		println "			--- ${it.class} $it"
	}
}

println "***** Before showing:"
printAvailableObjects(ImagePlus.class)

ui.show(img)

println "***** After showing:"
printAvailableObjects(ImagePlus.class)

null
Output (as expected)
***** Before showing:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
***** After showing:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
			--- class net.imagej.legacy.convert.ImageTitleToImagePlusConverter$ImageTitle 
			--- class net.imagej.DefaultDataset <unnamed data>
			--- class net.imagej.display.DefaultImageDisplay [net.imagej.display.DefaultDatasetView@670929a6]
  1. Run this second script, make some choice for the inputs, and click OK:
#@ ImagePlus imp1
#@ ImagePlus imp2
  1. Close the image window

  2. Run the script from step 1.) again, and observe this output:

***** Before showing:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
			--- class net.imagej.DefaultDataset <unnamed data>
			--- class net.imagej.display.DefaultImageDisplay [net.imagej.display.DefaultDatasetView@6968dbc3]
***** After showing:
		class ij.ImagePlus direct:
		class ij.ImagePlus converted:
			--- class net.imagej.legacy.convert.ImageTitleToImagePlusConverter$ImageTitle 
			--- class net.imagej.DefaultDataset <unnamed data>
			--- class net.imagej.DefaultDataset <unnamed data>
			--- class net.imagej.display.DefaultImageDisplay [net.imagej.display.DefaultDatasetView@6968dbc3]
			--- class net.imagej.display.DefaultImageDisplay [net.imagej.display.DefaultDatasetView@3863b7a8]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant