Skip to content

Instantly share code, notes, and snippets.

@will-moore
Last active March 18, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-moore/cea13a8092b7f48ea26e4aefc649a25b to your computer and use it in GitHub Desktop.
Save will-moore/cea13a8092b7f48ea26e4aefc649a25b to your computer and use it in GitHub Desktop.
createImageFromTiffs
# See https://www.openmicroscopy.org/community/viewtopic.php?f=4&t=8679
# and https://www.openmicroscopy.org/community/posting.php?mode=reply&f=6&t=8706
import omero
from omero.gateway import BlitzGateway
from PIL import Image
import numpy
conn = BlitzGateway("username", "password", host="localhost", port=4064)
conn.connect()
dataset = conn.getObject("Dataset", 25604)
# ----------- READ multiple TIFFs ---------------------------
image_paths = ["/path/to/image1.tif",
"/path/to/image2.tif"]
sizeC = len(image_paths)
imageName = "imageFromTiffs"
def plane_generator():
for path_to_image in image_paths:
img = Image.open(path_to_image)
# If this is an rgb tiff you may need to split the channels
np_array = numpy.asarray(img)
yield np_array
plane_gen = plane_generator()
newImg = conn.createImageFromNumpySeq(
plane_gen, imageName, sizeZ=1, sizeC=sizeC, sizeT=1, description='Test', dataset=dataset)
print "Created new Image:", newImg.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment