Skip to content

Instantly share code, notes, and snippets.

@sbesson
Last active April 21, 2020 15:21
Show Gist options
  • Save sbesson/e610bca6caf18e3f8ac8e1deaa06671b to your computer and use it in GitHub Desktop.
Save sbesson/e610bca6caf18e3f8ac8e1deaa06671b to your computer and use it in GitHub Desktop.
MATLAB example of writing tiled pyramidal OME-TIFF using the Bio-Formats API
writer = loci.formats.out.PyramidOMETiffWriter();
I0 = imread('rice.png');
I = cell(3,1);
I{1} = imresize(I0, 8);
I{2} = imresize(I0, 4);
I{3} = imresize(I0, 2);
I{4} = I0;
metadata = createMinimalOMEXMLMetadata(I{1});
toInt = @(x) javaObject('ome.xml.model.primitives.PositiveInteger', ...
javaObject('java.lang.Integer', x));
metadata.setResolutionSizeX(toInt(1024), 0, 1);
metadata.setResolutionSizeX(toInt(512), 0, 2);
metadata.setResolutionSizeX(toInt(256), 0, 3);
metadata.setResolutionSizeY(toInt(1024), 0, 1);
metadata.setResolutionSizeY(toInt(512), 0, 2);
metadata.setResolutionSizeY(toInt(256), 0, 3);
writer.setWriteSequentially(true);
writer.setMetadataRetrieve(metadata);
writer.setCompression('zlib');
writer.setBigTiff(true);
writer.setTileSizeX(256);
writer.setTileSizeY(256);
writer.setId('test.ome.tiff');
% Save planes to the writer
for i = 1 : 4
writer.setResolution(i - 1);
writer.saveBytes(0, I{i}(:));
end
writer.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment