Last active
April 21, 2020 15:21
-
-
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
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
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