We're Hiring!

Matlab bigtiff and compress

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

Matlab bigtiff and compress

Postby uutzinger » Fri May 17, 2013 12:42 am

How do I enable

1) bigtiff
2) LZW compression
with Matlab.

What will I need to change in bfsave?

Thanks.
uutzinger
 
Posts: 2
Joined: Fri May 17, 2013 12:38 am

Re: Matlab bigtiff and compress

Postby sbesson » Fri May 17, 2013 9:06 am

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
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: Matlab bigtiff and compress

Postby uutzinger » Tue May 21, 2013 11:00 pm

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);
uutzinger
 
Posts: 2
Joined: Fri May 17, 2013 12:38 am

Re: Matlab bigtiff and compress

Postby sbesson » Wed May 22, 2013 9:44 am

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
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest