Image Processing with Fiji and Omero
Introduction to OMERO
OMERO is an image management software package that allows you to organize, view, annotate, analyze, and share your data from a single centralized database. With OMERO, you and your collaborators can access your images from any computer without having to download the images directly to your computer.
In this chapter you will learn to view and manipulate images through the Fiji /ImageJ software package.
For more details, review the OMERO tutorial or visit the Research Computing website describing the UVA Omero Database Service.
Installation of Fiji and the OMERO Plugin
-
Install the Fiji application on your computer as described in this chapter.
-
Start Fiji and go to
Help
>Update
. This starts the updater which looks for plugin updates online. -
In the
ImageJ Updater
dialog window, click onManage Update Sites
. Ensure that the boxes for the following plugins are checked:-
Java-8
-
Bio-Formats
-
OMERO 5.4
-
-
Click
Close
. This will take you back to theImageJ Updater
window. -
Click
Apply Changes
. -
Restart Fiji.
Download the Example Scripts
To follow along, you can download the Jython scripts presented in this tutorial through this link.
Check your OMERO Database Account
-
If you are accessing the OMERO Database from an off-Grounds location, you have to connect through a UVA Virtual Private Network (VPN). Please follow these instructions to set up your VPN.
-
Open a web browser and go to http://omero.hpc.virginia.edu. Login to the OMERO web interface is described here.
-
Username: Your computing ID
-
Password: Your personal password
If you are new to UVA’s OMERO Database, a temporary password had been emailed to you.
Please change your temporary password when you log in for the first time to the Omero database server as described in these instructions.
-
-
You may be a member of multiple groups. For this workshop we want to specify
omero-demo
as the default group.
If you cannot log in, please submit a support request. Select Omero Image Analysis as Support Category.
Working with the OMERO Web Client and Desktop Applications
OMERO provides a group of client software to work with your imaging data.
-
OMERO.web is a web-based client for OMERO. At UVA you can use it by connecting to http://omero.hpc.virginia.edu. The Web client can be used to view images and metadata, and manage image tags, results, annotations, and attachments. It cannot be used to import data or measure regions-of-interest (see OMERO.insight).
-
View Data
-
Import Data
-
View Image Metadata
-
Manage Image Tags
-
Manage Results and Annotations
-
-
The two main additional features of OMERO.insight which are not available yet for OMERO.web are:
-
The Measurement Tool, a sub-application of ImageViewer that enables size and intensity measurements of defined regions-of-interest (ROIs), and
-
image import.
-
-
The OMERO Importer is part of the OMERO Desktop client but can also be run as a standalone application.
-
The OMERO.cli tools provide a set of administration and advanced command line tools written in Python.
For this workshop we will be using the OMERO Web client.
Projects, Datasets, Screens, Plates and Images
For this workshop we will be using prepared image sets and also upload new image data to your accounts. Omero organizes images in nested hierarchies of Projects
and Datasets
or Screens
and Plates
. The hierarchical nature is visualized as tree structures in the OMERO.web and OMERO.insight clients.
Images can be linked to individual projects, datasets, screens, or plates. A given image can be linked to multiple folders, allowing you to logically assign the same image to different folders without copying it. You can think of it like smart folders or symbolic links.
In addition, each group has a folder Orphaned Images
that contains images that have not been linked to any projects, datasets, screens, or plates.
Note: Each project, dataset, screen, plate, and image has a unique numerical ID that unambiguously identifies the data artifact. We use these numerical IDs rather than image, folder, or file names to get access to these elements.
Sample Data
Sample data has been added to the Fiji Omero Workshop
project. Inside the blue project folder you will find several dataset subfolders.
-
Group: omero-demo (Group ID:
53
) -
Project: Fiji Omero Workshop (Project ID:
130
)
Make note of the Group ID and Project ID.
Your Personal Projects and Datasets
Let’s create a new project and dataset through the OMERO web client.
-
In the left
Explore
panel, click onomero-demo
label and switch toAll Members
. Now you can see all data shared within theomero-demo
group. -
Right-click on the avatar with your name (or the “All Members” label). You can also just right click folder icon labeled
Fiji Omero Workshop
. In the popup menu, selectCreate new
>Project
. -
Name the new Project
<YOUR_UID>_workshop
, for examplemst3k_workshop
. -
Click on the blue folder icon of your new project and take note of the
Project ID
. We will need this to direct Fiji where to load data from or save data to. No right click on your blue project folder icon and create a new dataset. Right-click on the dataset icon and take note of theDataset ID
.
After the project is generated, your user interface should look like this:
Interactive Use of Fiji and OMERO
Uploading Images with the OMERO.insight client
Here we will demonstrate, the upload of a set of image files via the OMERO.insight client. The import process is described in our OMERO.insight Import Tutorial.
After the upload, the files are located in the following Project and Dataset:
-
Project: Fiji Omero Workshop (Project ID:
130
) -
Dataset: HeLa Cells (Dataset ID:
265
)
Note that images cannot be uploaded with the web-based OMERO.web client.
Uploading Images with Fiji
Images that have been opened and are displayed in the Fiji graphical user interface can be uploaded to OMERO using the File
> Export
> OMERO...
command. The naming of the tool can be confusing – it’s all a matter of perspective: Export from Fiji equates to an Import in OMERO. To minimize possible confusion we avoid these terms for the purpose of this workshop and refer to upload for any process that sends data to OMERO and download for any process that retrieves data from OMERO.
Before you begin, you need to know the dataset ID that the image should be linked to in OMERO. You can use the OMERO.web, OMERO.insight, or OMERO.cli tools to look up an appropriate dataset ID for this. Keep in mind that you can upload images only to those Projects and Datasets that you own.
-
If you choose a dataset ID -1, the image will be added to the
Orphaned Images
in your default OMERO group. For this workshop, we have chosen theomero-demo
group as default. -
Alternatively, you can export the image to a specific dataset in your default group, you just need to provide the dataset ID when executing the upload command.
Note: Image uploads via the built-in OMERO Export function is limited to your default group. This is not an issue if you belong to a single group. If you are a member of multiple groups, you can change your default group via the OMERO.web client.
Exercises
Export RGB image
-
File > Open Sample > Leaf (36k)
-
File > Export > OMERO…
Since we chose
Dataset: -1
, the uploaded image will end up inOrphaned Images
for your group. -
Go to OMERO webclient (http://omero.hpc.virginia.edu) and look for the uploaded image in
Orphaned Images
.
Export image stack to a specific dataset
-
In the OMERO webclient, create a new dataset under your personal workshop project. Make note of the dataset ID.
-
File > Open Samples > T1 Head (2.4M, 16-bit)
-
File > Export > OMERO…
Question: What happens when you repeatedly upload the same image to Omero?
Uploading Results with Fiji
-
In the OMERO.web client, make note of a dataset ID where you would like to upload a new image and associated results file to. You make pick the dataset ID from the previous exercise.
-
In Fiji, go to
File
>Open Samples
>Blobs (25K)
-
Let’s apply some basic filtering and simple image segmentation to identify all cellular outlines in the image:
a. Go to
Process
>Filter
>Median
. In the popup dialog enter aRadius
of3.0
and clickOK
. This will smooth out some of the image’s intrinsic noise without degrading the object outlines.b. Go to
Image
>Adjust Threshold
. In the popup dialog choose theDefault
thresholding algorithm, uncheck theDark Background
box and clickApply
. The image should have been converted to a binary mask with white objects ona black background.c. Go to
Analyze
>Set Measurements...
. In the popup dialog specify the parameters as shown in this screenshot. ClickOK
.d. Go to
Analyze
>Analyze Particles
and set up the parameters as shown. ClickOK
.e. These steps should create a
Results
and aSummary
table. -
Go to
File
>Export
>OMERO...
. Enter the dataset ID you chose under step 1 and clickOK
.
-
Click on the
Results
table window and go toFile
>Save As
. Save the file asResults.csv
on your computer. Repeat the same for theSummary
table. -
Upload the results files: Go to the OMERO web client, open the Dataset folder that you had chosen for the image upload. On the right side of the webpage, expand the
Attachments
pane and click on the+
icon. In the popup dialog, clickChoose File
and select the saved csv files. ClickAccept
.
Now you have analyzed the image and uploaded the image as well as all results to the OMERO dataset.
Scripting
Fiji provides convenient programming wrappers for the Fiji/ImageJ and OMERO functions that allow you to develop your scripts in a variety of programming languages:
- ImageJ macro language: simple, slow, not very versatile
- Jython: Python syntax with a few limitations, easy to learn, very versatile
- BeanShell: Syntax similar to Java, versatile
- Several others…
Fiji provides a richer programming environment than ImageJ and it is recommended to use Fiji instead of ImageJ for any script development. Our Fiji/ImageJ: Script development for Image Processing tutorial provides a more general introduction to this topic.
Example Scripts
To follow along, you can download the Jython scripts presented in this tutorial through this link.
The Script Editor
We’ll be using the built-in Script Editor in Fiji to run our scripts. To start the script editor in Fiji go to menu File
> New
> Script…
.
- The top pane provides the editor. Multiple scripts can be open at the same time and will show up as separate tabs.
- The bottom pane shows output (e.g. produced by print statements) and any errors encountered during script execution.
Script editor menus:
- File: Load, save scripts
- Edit: Similar to word processor functionality (Copy, Paste, etc.)
- Language: Choose language your script is written in with syntax highlighting
- Templates: Example scripts
- Tools: Access to source code of a class in the ImageJ/Fiji package
- Tabs: Navigation aid in script
The Macro Recorder
The Macro Recorder logs all commands entered through the Fiji graphical user interface (GUI). It is useful to convert these GUI actions into script commands.
- In the Fiji menu, go to
Plugins
>Macros…
>Record
.
- In the
Record
drop-down menu, selectBeanShell
. - Clicking the
Create
button copies the code to a new script in the Script Editor.
The Console Window
In the Fiji menu, go to Window
> Console
.
- The Console window shows the output and logging information produced by running plugins and scripts.
Connecting to OMERO
In order to get full access to OMERO’s programming interface, we will now use a more advanced approach to establish an authenticated connection with the OMERO database. We need instances of three classes: LoginCredientials
, SimpleLogger
, and Gateway
. The central one for the configuration is LoginCredentials
which has to be initialized with user specific credentials and database host information.
Our script would not be very useful or secure if we had to hardcode these values. Fortunately we can use the SciJava@Parameter annotation to prompt the script user for the relevant information:
#@ String (label="Omero User") username
#@ String (label="Omero Password", style="password") password
#@ String (label="Omero Server", value="omero.hpc.virginia.edu") server
#@ Integer (label="Omero Port", value=4064) port
These four lines at the top of our scripts are sufficient to create a dialog window that prompts the user for information that will be populated in the username
, password
, host
, and port
variables. With these variables in place we can now establish a connection to the OMERO database server.
cred = LoginCredentials()
if group_id != -1:
cred.setGroupID(group_id)
cred.getServer().setHostname(server)
cred.getServer().setPort(port)
cred.getUser().setUsername(username)
cred.getUser().setPassword(password)
simpleLogger = SimpleLogger()
gateway = Gateway(simpleLogger)
e = gateway.connect(cred)
The return value of the connect
method is stored as a boolean value in the variable e
. If e==True
, the connection was established; if e==False
, the connection failed. We can reuse this code block for most of our OMERO scripts.
It is very important to close the connection to the database at the end of your script, like this:
gateway.disconnect()
Getting the Basic OMERO Dataset Info
OMERO organizes users in groups. Each user can be a member of multiple groups. Images are organized in Projects and Datasets, or in Screens and Plates. The following script, Omero_Info.py
, connects a user to a remote OMERO instance and shows a list of:
- the groups that the user belongs to and the associated group ID. This ID is important when you want to access images stored for a particular group;
- the projects and datasets for a particular group (specified via unique group ID);
- and a list of images, organized by project and dataset, that the user has access to in a particular group.
The following script, Omero_info.py
establishes a connection to the OMERO database and outputs your OMERO group memberships, as well as a list of all of your projects, datasets, and images. The code contains separate functions to connect to the database, retrieve information from the database, and parse the data into a set of tables. If you’re just starting with programming, you may find it helpful to work through our
Fiji Scripting and other tutorials on our
learning portal.
(Click on the black triangle next to View to take a look at the script.)
View Omero_Info.py
script
|
|
Downloading Images from the OMERO database
Let’s try to download images from the database through a script. The OMERO plugin provides simple download (aka import to Fiji) functionality to achieve this.
-
In the OMERO web interface, click on any image in the
Fiji Omero Workshop
project or yourxxx_workshop
project/dataset and note the Image ID displayed in the sidebar on the right side of the webpage. Image retrieval relies on these unique image identifiers. -
Go back to the Fiji Script Editor and open the
Omero_Image_Download.py
script. -
Run the script. A dialog window will open; enter these values:
- Omero User: Your computing ID
- Omero Password: Your OMERO Password
- Omero Server: omero.hpc.virginia.edu
- Omero Port: 4064
- Omero Group ID: Enter
53
as ID for theomero-demo
group, or use-1
to use your default group - Image ID: Enter the ID for an image that is part of your
xxx_workshop
dataset, or use11980
from the example files.
The script consists of the these core blocks:
- Lines 1-6 define user input to connect to OMERO.
- Lines 12-20 define a
command
variable that specifies OMERO connection and image parameters. - Line 21 executes the OMERO importer plugin that retrieves the image.
|
|
Uploading Images to the OMERO database
Let’s try to upload an image from Fiji to OMERO.
-
Go back to Fiji and then to
File
>Open Samples
>Blobs
. -
Go back to the Fiji Script Editor and open the
Omero_Image_Upload.py file
.1 2 3 4 5
from ij import IJ imp = IJ.getImage() IJ.run(imp, "OMERO... ", "")
-
Run the script. The Export to OMERO dialog window will open. Enter the following values:
-
Server: omero.hpc.virginia.edu
-
Port: 4064
-
User: Your computing ID
-
Password: Your OMERO password
-
OMERO Dataset ID: Enter the ID for the
xxx_workshop
dataset that you created in the OMERO web interface. -
Check the Upload new image box. Leave the other boxes unchecked.
Click
OK
.If you see an error, make sure you entered the correct password and Dataset ID. Note: you have to use your own project/dataset.
-
-
Go to the OMERO website and refresh the page. Double-click on your
xxx_workshop
dataset icon to expand it. You should see the blobs.gif image.
Creating Key:Value Annotations
OMERO allows you to link other pieces of information to your Project, Dataset, Screen, Plate or Image objects. This additional information is displayed on the right side in the OMERO web client, labeled under the General
tab as Image Details
, Tags
, Key-Value Pairs
, Tables
, Attachments
, Comments
, and Ratings
. In addition, there is the Acquisition
tab that provides metadata information that was automatically extracted from the image file headers during import.
For the remainder of this workshop, we will focus on Key-Value
pairs and Attachments
. The key-value pairs are implemented as a dictionary (or HashMaps) that can be used to annotate individual images or whole datasets/project or plates/screens with additional information. Such information may include experimental conditions etc..
Let’s look at an example:
-
In the OMERO webclient, expand the
Fiji Omero Workshop
project folder and theSample Data
dataset folder inside it. -
Click on the
blobs.gif
image. In the general tab, you will see three entries under theKey-Value
group. (You may have to click on the triangle next to the label to expand the tab and see it).
The values displayed are not particular meaningful, but they illustrate the concept. You can create and modify annotations interactively through the OMERO client. In addition, you can manipulate key-value pairs (as well as other annotation categories) through Fiji scripts.
View Omero_Map_Annotation.py
script
|
|
Batch Processing and Results Tables for OMERO Datasets
The previous examples demonstrated how to export local images to OMERO, or how to import OMERO images to a local workstation. As the final exercise, let’s explore how an entire dataset comprised of many images can be downloaded from the remote OMERO instance, processed and analyzed locally, followed by an upload of the processed images and created results files back to the OMERO database.
The example script, Omero_Batch_Processing.py
, consists of five key functions:
- connect: Establishes a connection to the OMERO server with specific user credentials. It returns an instance of the OMERO
Gateway
class that is used later to upload processed images to the same OMERO server instance. - get_image_ids: Gets a list of unique image IDs for a given dataset managed by the remote OMERO instance.
- open_image: Downloads the image associated with an image ID and shows it in Fiji.
- process: Applies a custom image processing routine to a given image. In this case a basic segmentation and counting of cells.
- create_map_annotation: Uploads the cell count value to OMERO and links it to the original image.
- upload_csv_to_omero: Converts an ImageJ ResultsTable into a csv file, uploads that csv file and links it ot the original image objects.
- upload_image: Uploads an Image to a specific dataset managed by the remote OMERO instance.
Remember that the gateway connection needs to be closed at the end of the script.
To test this and see the process in action we will process a set of four images that has been deposited in the OMERO database. The setup is as follows:
-
Go to the OMERO webclient and make note of your
Project ID
, or you cna create a new project if you prefer. Again you need theID
. -
In the Fiji Script Editor, open the
Omero_Batch_Processing.py
script and execute it. -
In the popup window, specify the parameters as follows:
a. Replace the
mst3k
with your own credentials.b. Omero Input Dataset ID:
265
c. Omero Output Dataset Name: Enter name to your liking
d. Omero Output Project ID: Enter the
ID
that you looked up as step 1. The script will create a new dataset (with the name you chose) and place all the processed images in there. -
Click
OK
. Watch the console output for logging messages. -
After the script ru has completed, go to the OMERO webclient and open the Project that you had chosen to collect the output. Look for the
binary segmentation masks
, the attachedResults.csv
files and the newKey-Value Pairs
annotations for each image.
View Omero_Processing_Nuclei.py
script
|
|
Resources
OMERO
- OMERO: https://www.openmicroscopy.org/omero/
- OMERO User Support: https://help.openmicroscopy.org
- UVA Research Computing: https://www.rc.virginia.edu
- OMERO at the University of Virginia: https://www.rc.virginia.edu/userinfo/omero/overview/
Fiji Scripting
- RC tutorial Fiji/ImageJ: Script development for Image Processing
- Tutorial: https://syn.mrc-lmb.cam.ac.uk/acardona/fiji-tutorial/
- Tips for Developers: https://imagej.net/Tips_for_developers
- API: https://imagej.nih.gov/ij/developer/api/
- SciJava: https://javadoc.scijava.org/Fiji/
General Python Programming