generated from ome/guide-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jburel/python_ij_review
Python ij review
- Loading branch information
Showing
6 changed files
with
233 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Copyright (C) 2020 University of Dundee. All rights reserved. | ||
|
||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
# This script shows how to use the OMERO Python API and ImageJ Python. | ||
# We run a simple ImageJ1 macro. | ||
|
||
# Imports | ||
import imagej | ||
from omero.gateway import BlitzGateway | ||
|
||
|
||
# Step 1 - Load-Fiji | ||
def start_fiji(): | ||
ij = imagej.init('/srv/conda/vnc/Fiji.app', headless=False) | ||
ij.getVersion() | ||
return ij | ||
|
||
|
||
# Step 2 - Connect/Disconnect | ||
def connect(hostname, username, password): | ||
""" | ||
Connect to an OMERO server | ||
:param hostname: Host name | ||
:param username: User | ||
:param password: Password | ||
:return: Connected BlitzGateway | ||
""" | ||
conn = BlitzGateway(username, password, | ||
host=hostname, secure=True) | ||
conn.connect() | ||
conn.c.enableKeepAlive(60) | ||
return conn | ||
|
||
|
||
def disconnect(conn): | ||
""" | ||
Disconnect from an OMERO server | ||
:param conn: The BlitzGateway | ||
""" | ||
conn.close() | ||
|
||
|
||
# Step 4 - Load plane as 2D numpy array | ||
def load_plane(image): | ||
""" | ||
Load a 2D-plane as a numpy array | ||
:param image: The image | ||
""" | ||
pixels = image.getPrimaryPixels() | ||
return pixels.getPlane(0, 0, 0) | ||
|
||
|
||
# Step 5 - Wrap it all up | ||
def analyse(ij, conn, image_id): | ||
# Step 3 - Load image | ||
image = conn.getObject("Image", image_id) | ||
# - | ||
plane = load_plane(image) | ||
from jnius import autoclass | ||
autoclass('ij.WindowManager') | ||
ij.ui().show('Image', ij.py.to_java(plane)) | ||
macro = """run("8-bit")""" | ||
ij.py.run_macro(macro) | ||
|
||
|
||
def main(): | ||
try: | ||
hostname = input("Host [wss://idr.openmicroscopy.org/omero-ws]: \ | ||
") or "wss://idr.openmicroscopy.org/omero-ws" | ||
username = "public" | ||
password = "public" | ||
image_id = int(input("Image ID [1884807]: ") or 1884807) | ||
print("initializing fiji...") | ||
ij = start_fiji() | ||
print("connecting to IDR...") | ||
conn = connect(hostname, username, password) | ||
print("running the macro...") | ||
analyse(ij, conn, image_id) | ||
finally: | ||
if conn: | ||
disconnect(conn) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |