Best way imageJ to open an ImagePlus from OMERO using Bioformats

Hi,

The best way I’ve found so far to open an image in ImageJ from OMERO is based on this thread and this OMERO training script . I’ve attached the code at the end of question.

I’m a not fan of this because it the process is:

  • the scripts calls IJ.run
  • the image open and displays on the screen
  • the script grabs the most recently opened image window then hides it

It may be bit a of nitpick, but Is there a way to directly get the ImagePlus object by using the API? Something like:

from loci.plugins import BF
from loci.plugins.in import ImporterOptions
options  = ImporterOptions()
open.setId( omero_server_string )
imp = BF.openImagePlus(options)[0]

Thanks,

Chris

def open_image_plus(HOST, USERNAME, PASSWORD, PORT, group_id, image_id):
    "Open the image using the Bio-Formats Importer"

    options = ""
    options += "location=[OMERO] open=[omero:server="
    options += HOST
    options += "\nuser="
    options += USERNAME
    options += "\nport="
    options += str(PORT)
    options += "\npass="
    options += PASSWORD
    options += "\ngroupID="
    options += group_id
    options += "\niid="
    options += image_id
    options += "]"
    options += " windowless=true "
    IJ.runPlugIn("loci.plugins.LociImporter", options)```

Hi @evenhuis, that should work ok. So long as you are constructing the options the same as in https://github.com/ome/training-scripts/blob/master/practical/jython/analyse_particles_for_another_user.jy#L131 then you should be able to pass these to BF.openImagePlus as well.

Hi dgault,

Wow, you were right about the string having to be precisely constructed - even a stray whitespace will kill it.

I’ve cleaned things up a bit and I have been trying various combinations of feeding the options object the string constructed for IJ.runPlugin but nothing works for me.

  • options.setId(str_loc) errors with: (No such file or directory)… java.io.FileNotFoundException: java.io.FileNotFoundException
  • options.setLocation(..) errors with: this is not a possible value for whatever I try.

Similar what was observed in this thread,

trying to options.setLocation('OMERO') which from the code looks like it should work exits with this

Traceback (most recent call last):
  File "/Users/evenhuis/Dropbox/MIF/Workflows/omero-fiji-scripts/working_connection.py", line 207, in <module>
    open_image_plus(HOST, USERNAME, PASSWORD, PORT, group_id, image_id)
  File "/Users/evenhuis/Dropbox/MIF/Workflows/omero-fiji-scripts/working_connection.py", line 87, in open_image_plus
    options.setLocation(options.LOCATION_OMERO )
	at loci.plugins.prefs.StringOption.setValue(StringOption.java:130)
	at loci.plugins.prefs.OptionsList.setValue(OptionsList.java:167)
	at loci.plugins.in.ImporterOptions.setLocation(ImporterOptions.java:303)
	at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: 'OMERO' is not a possible value

The javadocs for ImporterOptions are rather sparse and I’ve tried looking through on GitHub but I couldn’t find anything.

Could you please share an example of how to setup ImportOptions for an Omero file?

Thanks,

Chris

def open_image_plus(HOST, USERNAME, PASSWORD, PORT, group_id, image_id):
	"Open the image using the Bio-Formats Importer"

	loc_args=[HOST,USERNAME,PORT,PASSWORD,group_id,image_id]
	str_loc = "location=[OMERO] open=[omero:server={}\nuser={}\nport={}\npass={}\ngroupID={}\niid={}]".format(*loc_args)
	str_server="[omero:server={}\nuser={}\nport={}\npass={}\ngroupID={}\niid={}]".format(*loc_args)

	# this works
	IJ.runPlugIn("loci.plugins.LociImporter", str_loc+" windowless=true")

	# I can't get this to work
	from loci.plugins import BF
	from loci.plugins.in import ImporterOptions
	options  = ImporterOptions()
	#options.setLocation(str_server)
	options.setId( str_loc )
	imp=BF.openImagePlus(options)[0]

After a bit of debugging it seems the reason you cant set OMERO directly as a location is because by default creating ImporterOptions limits the possible values to local machine or internet. Really this was never designed for end users to be accessing OMERO images in this manner. If you wish to override it though then calling the below after creating the ImporterOptions will set the location to OMERO:
options.parseArg('location=[OMERO]')

At this point though I would recommend sticking with the original recommended method of calling LociImporter as per the OMERO training script.

Hi dgault,

thanks for that. On a similar note, I’ve never been able to work out how to setup filename pattern matching through the bio formats API and resorted to throwing strings at IJ.run.

One dumb question about opening an image hosted on OMERO with the bioformats importer in Fiji.

When I request a single channel slice from a multi-point, Z-stack time-lapse hosted on OMERO is it:

  1. Preparing the pixels server side sending a single 2D image to Fiji, or
  2. Downloading the raw image file from OMERO, parsing with the local BioFormats importer, then presenting the single 2D image

The reason I ask is that we have a lot of well plate work done with Nikons that are in a single >25GB file. Transferring them to OMERO takes a a lot of time and CPU, even opening a local copy causes Fiji to churn for long time.

Thanks,

Chris

Hi dgault,

I was just playing with the loci importer to understand how it is retrieving images from OMERO.

I have been experimenting with a multi-point timelapse using this approach:

	loc_args=[HOST,USERNAME,PORT,PASSWORD,group_id,image_id]
	str_loc = "location=[OMERO] open=[omero:server={}\nuser={}\nport={}\npass={}\ngroupID={}\niid={}] ".format(*loc_args)
	str_opt =  "  autoscale color_mode=Grayscale rois_import=[ROI manager] specify_range view=Hyperstack stack_order=XYCZT series_1 t_begin_1=1 t_end_1=5 t_step_1=1"
	IJ.runPlugIn("loci.plugins.LociImporter", str_loc+str_opt)

From my tinkering:

  • Individual series (multi-point locations) are opened
  • The begin / end commands are not used
  • When I have mistake in str_opt (like misspelling color) the whole time series is loaded first, then the error is raised.

This would suggest that:

  • the multi-point has either been split up and stored as OME tif in OMERO or is being processed on the server before being sent to local Fiji.
  • the importer does not use the “Specify range arguments” .

Is this the right model for the OMERO - ImageJ connection?

Cheers,

Chris

Hi Chris

We have 2 examples scripts that might be useful for what you want to achieve

Cheers

Jmarie

Is it aslo possible to get the images without showing them,
I want to have users select a dataset, and a plugin and then combine them without them seeing the images pop up all the time.

Joost

Hi Joost

There is no direct way when starting the plugin not to display the ImagePlus created.
If you images are stored in OMERO, you will first need to download the images locally
and then directly use Bio-Formats to read the images
[1] shows how to download an image in OMERO using groovy
[2] shows how to open the image using B-F.

It might be easier to have the image popping up for a brief period of time to avoid a lot of code

Cheers
Jmarie

[1] https://github.com/ome/training-scripts/blob/master/practical/groov/open_image_after_download.groovy
[2] https://imagej.net/index.php?title=Jython_Scripting_Examples&mobileaction=toggle_view_desktop#Open_all_series_in_a_LIF_file_with_Bio-Formats

I thought that was the purpose of the OMEROService#downloadImage(client, imageID) method from the imagej-omero project.

Maybe @ctrueden or @awalter17 can shed some light on this…

1 Like

Ok, tried that but it gives an error like this

net.imagej.omero.DefaultOMEROService.downloadImage(DefaultOMEROService.java:514)

so i went into the Defaultomreoservicecode, and checked line 514.
This is where the SCIFIO config is created.

So i took those libraries and tried to recreate the downloadImage code.
This give an error with the datasetIOService.

I thought to go further into that, but i cannot find how the datasetIOService gets initiated. If i initiate it as a DefaultDatasetIOservice it doesn’t work and gives a

org.scijava.Contextual.setContext(Contextual.java:79)
io.scif.img.AbstractImgIOComponent.<init>(AbstractImgIOComponent.java:60)
io.scif.img.ImgOpener.<init>(ImgOpener.java:98)

error. I also cannot initialize it as null.
Also when i use the legacyOmeroService it doesn’t work

Could use some help
Thanks imagejan for getting me started on this btw

@Joost_Willemse1 Could you please post the entire stack trace?

Happy to help, if you can post more information. I’d like the whole stack trace, as well as your relevant source code—ideally a minimal working example demonstrating the issue.

Please be aware that the ImageJ-OMERO project is built against ImageJ2 and its data structures, while all of the documentation from the OME team targets ImageJ1. Which data structures (ImageJ1 or ImageJ2) do you use in your ImageJ scripts?

Of course,

The stacktrace:

net.imagej.omero.DefaultOMEROService.downloadImage(DefaultOMEROService.java:514)
LeidenUniv.Omero.getOmeroDatasetMinimal_.openImagePlus(getOmeroDatasetMinimal_.java:31)
LeidenUniv.Omero.getOmeroDatasetMinimal_.getDatasetImages(getOmeroDatasetMinimal_.java:84)
LeidenUniv.Omero.getOmeroDatasetMinimal_.main(getOmeroDatasetMinimal_.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.scijava.main.run.MainCodeRunner.run(MainCodeRunner.java:66)
org.scijava.run.RunService.run(RunService.java:59)
org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:137)
org.scijava.script.ScriptModule.run(ScriptModule.java:160)
org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

The code im using:

package LeidenUniv.Omero;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.GridBagConstraints;
import ij.IJ;
import ij.ImagePlus;
import omero.gateway.Gateway;
import omero.gateway.LoginCredentials;
import omero.log.SimpleLogger;
import ij.gui.GenericDialog;
import net.imagej.omero.*;
import net.imagej.Dataset;
import omero.client;
import net.imglib2.img.imageplus.ImagePlusImg;
import net.imagej.omero.legacy.LegacyOMEROService;

public class getOmeroDatasetMinimal_ {
    private String Username = "";
    private static String HOST;
    private static int PORT = 4064;
    private String Password = "";
	private long imageId;

	private ImagePlus openImagePlus(long imageId) throws Exception{
		OMEROLocation ol = new OMEROLocation(HOST,PORT,Username,Password);
		LegacyOMEROService dos = new LegacyOMEROService();
		OMEROSession os = dos.createSession(ol);
		client cl = os.getClient();
		ImagePlus ip=null;
		try{
			Dataset d = dos.downloadImage(cl,imageId);
			ip = ((ImagePlusImg)d.getImgPlus().getImg()).getImagePlus();
			ip.show();
		} catch (Exception e){
			IJ.log(e.getMessage());
        	StackTraceElement[] t = e.getStackTrace();
        	for (int i=0;i<t.length;i++){
        		IJ.log(t[i].toString());
        	}
		}
		return ip;	
	}
     
    private Gateway connectToOMERO() throws Exception {
		GenericDialog userData = new GenericDialog("Fill in login information");
		GridBagConstraints gb = new GridBagConstraints();
        gb.gridx=GridBagConstraints.RELATIVE;
        gb.anchor=GridBagConstraints.WEST;
        gb.insets.left=20;
        userData.addMessage("Host");
        JTextField tf1 = new JTextField(25);
        userData.add(tf1, gb);
        userData.addMessage("");
        userData.addMessage("Username");
        JTextField tf = new JTextField(25);
        userData.add(tf, gb);
        userData.addMessage("");
        userData.addMessage("Password");
        JPasswordField jp = new JPasswordField(25);
        userData.add(jp, gb);
        userData.addMessage("");
        userData.addMessage("");      
        JTextField tf2 = new JTextField(15);
        userData.add(tf2, gb);
        userData.addMessage("");
        userData.addMessage("ImageId");
        userData.showDialog();
        HOST = tf1.getText();
        Username = tf.getText();
        imageId=Long.parseLong(tf2.getText());
        char[] ch = jp.getPassword();
        Password = new String(ch);
        LoginCredentials credentials = new LoginCredentials(Username,Password,HOST,PORT);
        SimpleLogger simpleLogger = new SimpleLogger();
        Gateway gateway = new Gateway(simpleLogger);
        gateway.connect(credentials);
        return gateway;
    }
	
    public void getDatasetImages() {
        Gateway gateway = null;
        try {
			gateway = connectToOMERO(); // gets omero info
            openImagePlus(imageId);
        } catch (Exception e) {
        	IJ.log(e.getMessage());
        	StackTraceElement[] t = e.getStackTrace();
        	for (int i=0;i<t.length;i++){
        		IJ.log(t[i].toString());
        	}
            IJ.showMessage("An error occurred while loading the image.");
        } finally {
            if (gateway != null) gateway.disconnect();
        }
    }
// used for testing when running the plugin stand alone
    public static void main(String[] args) {
    	IJ.log("\\Clear");
    	getOmeroDatasetMinimal_ om = new getOmeroDatasetMinimal_();
        om.getDatasetImages();
    }
}

The main code just gets the login information.
The openImagePlus part is where the error comes from.
The error originates from this line

Dataset d = dos.downloadImage(cl,imageId);

This can be located to the line

new SCIFIOConfig().imgOpenerSetImgModes(ImgMode.CELL);

If i try to recreate the part from the defaultOmeroService the stacktrace becomes

org.scijava.Contextual.setContext(Contextual.java:79)
io.scif.img.AbstractImgIOComponent.<init>(AbstractImgIOComponent.java:60)
io.scif.img.ImgOpener.<init>(ImgOpener.java:98)
io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:117)

Hi,

I just a had try at loading the library and it appears that omero is not the namespace of net.imagej. Minimal python script

import  net.imagej as imagej
from  net.imagej import ops, plugins, ui, legacy

print("Loads sucessfully")
for d in dir(imagej):
	print("   "+d)

print("Error on this import")
from  net.imagej import omero

Error message

Started New_.py at Wed Jan 29 12:58:03 AEDT 2020
Traceback (most recent call last):
  File "New_.py", line 9, in <module>
ImportError: cannot import name omero

	at org.python.core.Py.ImportError(Py.java:334)
	at org.python.core.imp.importFromAs(imp.java:1161)
	at org.python.core.imp.importFrom(imp.java:1124)
	at org.python.pycode._pyx108.f$0(New_.py:9)
	at org.python.pycode._pyx108.call_function(New_.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	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$2(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)

I’m using ImageJ version 2.0.0-rc-71/1.52p, not sure about the scijava version number.

Personally, I use mostly imageJ1 but I am slowly learning more ImageJ2 / imglib2. Would just be matter of wrapping with net.imglib2.img.display.imagej.ImageJFunctions.wrap?

Thanks,

Chris

@Joost_Willemse1 SciJava services are not intended to be instantiated directly. Instead, obtain it from the active SciJava context:

OMEROLocation ol = new OMEROLocation(HOST,PORT,Username,Password);
OMEROService omeroService = context.service(OMEROService.class);

And go from there.

If you don’t have an org.scijava.Context object, you can make one as follows:

import net.imagej.ImageJ;
...
ImageJ ij = new ImageJ();
Context context = ij.context();

Or if you don’t want to use the net.imagej.ImageJ gateway:

import org.scijava.Context;
...
Context context = new Context();

Exactly what this context contains will depend on your classpath. In particular, make sure you have net.imagej:imagej-omero and net.imagej:imagej-omero-legacy included.

However: from your stack trace, it appears you’re invoking your main method indirectly using the SciJava main method runner. How are you doing that? By opening the getOmeroDatasetMinimal_ class in the Script Editor and running it from there? If so, then there is already a SciJava context established, which you should reuse instead of creating a new one. I would advise you to structure your code as a Command plugin instead, because then you can just add an @Parameter OMEROService omeroService; field to your class and it will be populated for you.

Happy to clarify further if anything needs more explanation.

1 Like

Ah, thats where i went wrong, I now get the context from imageJ and it all works out.

Now managing to get the omero files imported and not showing up.
Thanks for the help.

1 Like

Hi @Joost_Willemse1 and @ctrueden,

that sounds great, I’ve been looking for better way to access images from OMERO. I’m having trouble getting the solution to work. Could you please share a minimal working example as suggested by ctrueden above?

Following ctrueden’s advice above, I can generate a context using:

from net.imagej import ImageJ

ij =  ImageJ()
context = ij.context()

for service in  context.getServiceIndex():
	ident = service.identifier
	print(ident)

I can see the list of services but I can’t see anything related to OMERO in there. I hav the OMERO plugin installed and can connect using the plugin and from scripts using using omero.gateway. is there something I need to do install the OMERO service?

If I have the OMERO service running, from the context javadoc it looks like the only way to get the service would be like

omero_class string = "net.imagej.omero.OMEROService"  # Not sure about this
context.service( omero_class_string )

as the OMEROService class can’t be imported?

Thanks,

Chris

List of services

Started ij2_method.py at Wed Feb 05 09:26:25 AEDT 2020
plugin:org.scijava.event.DefaultEventService
plugin:net.imagej.legacy.display.LegacyImageDisplayService
plugin:net.imagej.lut.DefaultLUTService
plugin:net.imagej.legacy.LegacyService
plugin:fiji.DefaultFijiService
plugin:io.scif.DefaultMetadataService
plugin:io.scif.codec.DefaultCodecService
plugin:io.scif.formats.qt.DefaultQTJavaService
plugin:io.scif.formats.tiff.DefaultTiffService
plugin:io.scif.gui.DefaultGUIService
plugin:io.scif.img.DefaultImgUtilityService
plugin:io.scif.img.converters.DefaultPlaneConverterService
plugin:io.scif.io.DefaultNIOService
plugin:io.scif.ome.services.DefaultOMEMetadataService
plugin:io.scif.ome.services.DefaultOMEXMLService
plugin:io.scif.refs.DefaultRefManagerService
plugin:io.scif.services.DefaultDatasetIOService
plugin:io.scif.services.DefaultFilePatternService
plugin:io.scif.services.DefaultFormatService
plugin:io.scif.services.DefaultLocationService
plugin:io.scif.services.DefaultTranslatorService
plugin:io.scif.services.JAIIIOServiceImpl
plugin:io.scif.xml.DefaultXMLService
plugin:net.imagej.DefaultDatasetService
plugin:net.imagej.DefaultImgPlusService
plugin:net.imagej.animation.DefaultAnimationService
plugin:net.imagej.autoscale.DefaultAutoscaleService
plugin:net.imagej.display.DefaultImageDisplayService
plugin:net.imagej.display.DefaultOverlayService
plugin:net.imagej.display.DefaultWindowService
plugin:net.imagej.display.DefaultZoomService
plugin:net.imagej.legacy.plugin.MacroExtensionAutoCompletionService
plugin:net.imagej.measure.DefaultMeasurementService
plugin:net.imagej.measure.DefaultStatisticsService
plugin:net.imagej.notebook.DefaultImageJNotebookService
plugin:net.imagej.notebook.DefaultNotebookService
plugin:net.imagej.operator.DefaultCalculatorService
plugin:net.imagej.ops.DefaultNamespaceService
plugin:net.imagej.ops.DefaultOpMatchingService
plugin:net.imagej.ops.DefaultOpService
plugin:net.imagej.roi.DefaultROIService
plugin:net.imagej.sampler.DefaultSamplerService
plugin:net.imagej.table.DefaultTableService
plugin:net.imagej.threshold.DefaultThresholdService
plugin:net.imagej.types.DefaultDataTypeService
plugin:net.imagej.ui.DefaultImageJUIService
plugin:net.imagej.ui.awt.AWTRenderingService
plugin:net.imagej.ui.awt.AWTScreenCaptureService
plugin:net.imagej.ui.swing.ops.DefaultOpFinderService
plugin:net.imagej.ui.swing.overlay.JHotDrawService
plugin:net.imagej.units.DefaultUnitService
plugin:net.imagej.updater.DefaultUpdateService
plugin:net.imagej.updater.DefaultUploaderService
plugin:org.scijava.app.DefaultAppService
plugin:org.scijava.app.DefaultStatusService
plugin:org.scijava.command.DefaultCommandService
plugin:org.scijava.console.DefaultConsoleService
plugin:org.scijava.convert.DefaultConvertService
plugin:org.scijava.display.DefaultDisplayService
plugin:org.scijava.download.DefaultDownloadService
plugin:org.scijava.event.DefaultEventHistory
plugin:org.scijava.input.DefaultInputService
plugin:org.scijava.io.DefaultIOService
plugin:org.scijava.io.DefaultRecentFileService
plugin:org.scijava.io.handle.DefaultDataHandleService
plugin:org.scijava.io.location.DefaultLocationService
plugin:org.scijava.io.nio.DefaultNIOService
plugin:org.scijava.jupyter.service.DefaultJupyterService
plugin:org.scijava.main.DefaultMainService
plugin:org.scijava.menu.DefaultMenuService
plugin:org.scijava.module.DefaultModuleService
plugin:org.scijava.notebook.DefaultNotebookService
plugin:org.scijava.object.DefaultObjectService
plugin:org.scijava.options.DefaultOptionsService
plugin:org.scijava.parse.DefaultParseService
plugin:org.scijava.platform.DefaultPlatformService
plugin:org.scijava.plugin.DefaultPluginService
plugin:org.scijava.prefs.DefaultPrefService
plugin:org.scijava.run.DefaultRunService
plugin:org.scijava.script.DefaultScriptHeaderService
plugin:org.scijava.script.DefaultScriptService
plugin:org.scijava.script.process.DefaultScriptProcessorService
plugin:org.scijava.search.DefaultSearchService
plugin:org.scijava.search.javadoc.DefaultJavadocService
plugin:org.scijava.startup.DefaultStartupService
plugin:org.scijava.task.DefaultTaskService
plugin:org.scijava.text.DefaultTextService
plugin:org.scijava.thread.DefaultThreadService
plugin:org.scijava.tool.DefaultToolService
plugin:org.scijava.ui.DefaultUIService
plugin:org.scijava.ui.dnd.DefaultDragAndDropService
plugin:org.scijava.ui.swing.SwingIconService
plugin:org.scijava.ui.swing.script.DefaultLanguageSupportService
plugin:org.scijava.welcome.DefaultWelcomeService
plugin:org.scijava.widget.DefaultWidgetService
plugin:sc.fiji.compat.DefaultFijiService
plugin:sc.iview.DefaultSciViewService
plugin:io.scif.services.DefaultInitializeService
plugin:net.imagej.display.DummyScreenCaptureService
plugin:net.imagej.render.DummyRenderingService
plugin:org.scijava.batch.FileBatchService
plugin:org.scijava.log.StderrLogService
plugin:org.scijava.platform.DefaultAppEventService
plugin:org.scijava.cache.DefaultCacheService

Ok, i threw out all the code making it more complicated and ended up with these 50 lines to get my image displayed

import ij.IJ;
import ij.ImagePlus;
import omero.gateway.Gateway;
import omero.gateway.LoginCredentials;
import omero.log.SimpleLogger;
import net.imagej.omero.*;
import net.imagej.Dataset;
import net.imagej.ImageJ;
import net.imagej.ImgPlus;
import omero.client;
import net.imglib2.img.imageplus.ImagePlusImg;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imagej.omero.legacy.LegacyOMEROService;
import org.scijava.Context;

public class getOmeroDatasetSuperMinimal {
    private String Username = "Username";
    private static String HOST = "server";
    private static int PORT = 4064;
    private String Password = "password";
	private long imageId=imageid;

    public void getDatasetImages() {
        Gateway gateway = null;
        try {
			LoginCredentials credentials = new LoginCredentials(Username,Password,HOST,PORT);
        	SimpleLogger simpleLogger = new SimpleLogger();
       		gateway = new Gateway(simpleLogger);
        	gateway.connect(credentials);
        	OMEROLocation ol = new OMEROLocation(HOST,PORT,Username,Password);
			ImageJ ij = new ImageJ();
			Context context = ij.context();
			OMEROService dos = context.service(OMEROService.class);
			OMEROSession os = dos.createSession(ol);
			client cl = os.getClient();
            Dataset d = dos.downloadImage(cl,imageId);
            ImgPlus implu=d.getImgPlus();
            ImageJFunctions.show(implu.getImg());
        } catch (Exception e) {
            IJ.showMessage("An error occurred while loading the image.");
        } finally {
            if (gateway != null) gateway.disconnect();
        }
    }
// used for testing when running the plugin stand alone
    public static void main(String[] args) {
    	getOmeroDatasetSuperMinimal om = new getOmeroDatasetSuperMinimal();
        om.getDatasetImages();
    }
}

As usual, i get into the next issue,

I can only open images from the default group. No idea why that would be, any suggestions?

@evenhuis From your list of services, it looks like you are running Fiji. So you probably don’t have the net.imagej:imagej-omero and net.imagej:imagej-omero-legacy artifacts on your classpath? Did you enable the OMERO update site?

From your script, it looks like you are using Jython? Are you running that from inside Fiji’s Script Editor? If so, do not make a new ImageJ() object, but instead use script parameters:

#@ OMEROService omeroService
omeroService.doAllTheThings()

@Joost_Willemse1 I’ll have to defer to the @ome team (@OMETeam?) on that one. But I’m guessing it’s related to the group context of the OMERO connection. Changes might be needed to ImageJ-OMERO to make this work better—if so, please let me know. (And PRs warmly welcomed!)

1 Like