Created
May 23, 2014 15:00
-
-
Save will-moore/93f50213055d37d0f049 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from omero.gateway import * | |
from omero.model import * | |
from omero.rtypes import * | |
from omero.util.tiles import * | |
from numpy import fromfunction | |
user = 'will' | |
pw = 'ome' | |
host = 'localhost' | |
conn = BlitzGateway(user, pw, host=host, port=4064) | |
conn.connect() | |
sizeX = 4096 | |
sizeY = 4096 | |
sizeZ = 1 | |
sizeC = 1 | |
sizeT = 1 | |
tileWidth = 1024 | |
tileHeight = 1024 | |
imageName = "testStitchBig4K-1Ktiles" | |
description = None | |
tile_max = 255 | |
pixelsService = conn.getPixelsService() | |
queryService = conn.getQueryService() | |
query = "from PixelsType as p where p.value='int8'" | |
pixelsType = queryService.findByQuery(query, None) | |
channelList = range(sizeC) | |
bytesPerPixel = pixelsType.bitSize.val / 8 | |
iId = pixelsService.createImage( | |
sizeX, | |
sizeY, | |
sizeZ, | |
sizeT, | |
channelList, | |
pixelsType, | |
imageName, | |
description, | |
conn.SERVICE_OPTS) | |
image = conn.getObject("Image", iId) | |
pid = image.getPixelsId() | |
def f(x, y): | |
""" | |
create some fake pixel data tile (2D numpy array) | |
""" | |
return (x * y)/(1 + x + y) | |
def mktile(w, h): | |
tile = fromfunction(f, (w, h)) | |
tile = tile.astype(int) | |
tile[tile > tile_max] = tile_max | |
return list(tile.flatten()) | |
tile = fromfunction(f, (tileWidth, tileHeight)).astype(int) | |
tile_min = float(tile.min()) | |
tile_max = min(tile_max, float(tile.max())) | |
from random import random | |
class Iteration(TileLoopIteration): | |
def run(self, data, z, c, t, x, y, tileWidth, tileHeight, tileCount): | |
wh = int(1024 * random()) | |
tile2d = mktile(wh, wh) | |
print "run x, y, tileWidth, tileHeight, tileCount", x, y, wh, wh, tileCount | |
data.setTile(tile2d, z, c, t, x, y, wh, wh) | |
loop = RPSTileLoop(conn.c.sf, PixelsI(pid, False)) | |
loop.forEachTile(1024, 1024, Iteration()) | |
c = 0 | |
pixelsService.setChannelGlobalMinMax( | |
pid, c, tile_min, tile_max, conn.SERVICE_OPTS) | |
conn._closeSession() | |
print "Image", iId.val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment