Page 1 of 1

Matlab bigtiff and compress

PostPosted: Fri May 17, 2013 12:42 am
by uutzinger
How do I enable

1) bigtiff
2) LZW compression
with Matlab.

What will I need to change in bfsave?

Thanks.

Re: Matlab bigtiff and compress

PostPosted: Fri May 17, 2013 9:06 am
by sbesson
Hi,

Thanks for your question, These options are not exposed in the current version of the save function and we will open a Pull Request to implement them soon, in the mean time you should be able to set both options by using the following code block:

Code: Select all
writer = loci.formats.ImageWriter();
writer.setWriteSequentially(true);
writer.setMetadataRetrieve(metadata);
writer.setCompression('LZW')
writer.getWriter(outputPath).setBigTiff(true)
writer.setId(outputPath);


Cheers,
Sebastien

Re: Matlab bigtiff and compress

PostPosted: Tue May 21, 2013 11:00 pm
by uutzinger
This was very helpful. Following code segments will expand bfsave on windows to include bigtiff and compression support:

% INPUT:
% I - a 5D matrix containing the pixels data
%
% outputPath - a string containing the location of the path where to
% save the resulting OME-TIFF
%
% dimensionOrder - optional. A string representing the dimension
% order, Default: XYZCT.
%
% Compression - use zlib, bzip2, none, LZW, JPEG, JPEG-2000,
% Uncompressed
% zlib is not available on Windows and results in no compression
% JPEG is very slow
%
% bigTiff - use 64 bit tiff tags, true or false

% List all values of Compression
CompressionValues = ome.xml.model.enums.Compression.values();
Compressions = cell(numel(CompressionValues)+4, 1);
for i = 1 :numel(CompressionValues),
Compressions{i} = char(CompressionValues(i).toString());
end
Compressions{numel(CompressionValues)+1}='LZW'; % Error in OME xml, lists only unix compressors
Compressions{numel(CompressionValues)+2}='JPEG'; % Error in OME xml, lists only unix compressors
Compressions{numel(CompressionValues)+3}='Uncompressed'; % Error in OME xml, lists only unix compressors
Compressions{numel(CompressionValues)+4}='JPEG-2000'; % Error in OME xml, lists only unix compressors

.. some code here ...

ip.addOptional('dimensionOrder', 'XYZCT', @(x) ismember(x, dimensionsOrders));
ip.addOptional('Compression', 'zlib', @(x) ismember(x, Compressions));
ip.addOptional('bigTiff', false , @islogical);

.. some code here ...

% Create ImageWriter
writer = loci.formats.ImageWriter();
writer.setWriteSequentially(true);
writer.setMetadataRetrieve(metadata);
if ~strcmp(ip.Results.Compression, 'none')
writer.setCompression(ip.Results.Compression)
end
writer.getWriter(outputPath).setBigTiff(ip.Results.bigTiff)
writer.setId(outputPath);

Re: Matlab bigtiff and compress

PostPosted: Wed May 22, 2013 9:44 am
by sbesson
Hi and thanks for your great feedback,

I just opened a Pull Request to add these options to the core bfsave function. I don't have a Windows box here and I am unable to test the Windows compression issues but thanks for mentioning them as we'll try to reproduce them.

Also for the compression values, you may want to use
Code: Select all
loci.formats.ImageWriter().getCompressionTypes

to list the available compressions.

Sebastien