-
-
Save joshmoore/816cdf461669a7e06d46 to your computer and use it in GitHub Desktop.
Tile Writing
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
from omero.gateway import * | |
from omero.model import * | |
from omero.rtypes import * | |
from omero.util.tiles import * | |
from numpy import fromfunction | |
user = '2448' | |
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())) | |
class Iteration(TileLoopIteration): | |
def run(self, data, z, c, t, x, y, tileWidth, tileHeight, tileCount): | |
tile2d = mktile(tileWidth, tileHeight) | |
data.setTile(tile2d, z, c, t, x, y, tileWidth, tileHeight) | |
loop = RPSTileLoop(conn.c.sf, PixelsI(pid, False)) | |
loop.forEachTile(256, 256, 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