OME Community Meeting
Dundee May 2020
OME Team
bfconvert -compression LZW /path/to/input out.ome.tiff
bfconvert -tilex 512 -tiley 512 /path/to/input out.ome.tiff
bfconvert -noflat -pyramid-resolutions 4 -pyramid-scale 2 /path/to/input out.ome.tiff
# setup reader
reader = ImageReader()
omeMeta = MetadataTools.createOMEXMLMetadata()
reader.setMetadataStore(omeMeta)
reader.setId(file)
# setup writer
writer = PyramidOMETiffWriter()
writer.setMetadataRetrieve(omeMeta)
writer.setId(outFile)
for series in range(reader.getSeriesCount()):
reader.setSeries(series)
writer.setSeries(series)
# convert each image in the current series
for image in range(reader.getImageCount())
# read and write image planes
img = reader.openBytes(image)
writer.saveBytes(image, img)
width = reader.getSizeX();
height = reader.getSizeY();
# Determined the number of tiles to read and write
nXTiles = int(math.floor(width / tileSizeX))
nYTiles = int(math.floor(height / tileSizeY))
if nXTiles * tileSizeX != width:
nXTiles = nXTiles + 1
if nYTiles * tileSizeY != height:
nYTiles = nYTiles + 1
for y in range(nYTiles):
for x in range(nXTiles):
# The x and y coordinates for the current tile
tileX = x * tileSizeX
tileY = y * tileSizeY
# Read tiles from the input file and write them to the output OME-Tiff
buf = reader.openBytes(image, tileX, tileY, tileSizeX, tileSizeY)
writer.saveBytes(image, buf, tileX, tileY, tileSizeX, tileSizeY)
# setup resolutions
for i in range(resolutions):
divScale = Math.pow(scale, i + 1)
omeMeta.setResolutionSizeX(PositiveInteger(int(reader.getSizeX() / divScale)), 0, i + 1)
omeMeta.setResolutionSizeY(PositiveInteger(int(reader.getSizeY() / divScale)), 0, i + 1)
# create ImageScaler for down-sampling
scaler = SimpleImageScaler()
# read and write main image
img = reader.openBytes(0)
writer.saveBytes(0, img)
# generate downsampled resolutions and write to output
for i in range(resolutions):
writer.setResolution(i + 1)
x = omeMeta.getResolutionSizeX(0, i + 1).getValue()
y = omeMeta.getResolutionSizeY(0, i + 1).getValue()
downsample = scaler.downsample(img, reader.getSizeX(), reader.getSizeY(), Math.pow(scale, i + 1),
FormatTools.getBytesPerPixel(type), reader.isLittleEndian(),
FormatTools.isFloatingPoint(type), reader.getRGBChannelCount(),reader.isInterleaved())
writer.saveBytes(0, downsample)