TiffSaver

class io.savers.TiffSaver

Bases: io.savers.BaseSaver

TIFFSAVER - Saver for TIFF (Tagged Image File Format) output.

Handles three format variants: ‘TIF format uncompressed (*.tif)’ - no compression, broadest compat. ‘TIF format LZW compression (*.tif)’ - lossless LZW, smaller files ‘TIF format (*.tif)’ - alias used for mask/labels export

Both 3-D multi-frame TIF (all slices in one file) and 2-D sequence (one file per slice) modes are supported via options.Saving3DPolicy.

DATA DIMENSIONS Input data : [H, W, D, C, T] (MIB3 native order) imwrite call: [H, W, C] per individual Z-slice [H, W, C, D] for the full Z-stack in multi mode

NOTES * TIFF supports at most 3 colour channels via standard imwrite. Multichannel data with C > 3 is not supported; use Amira or HDF5. * Indexed images (colorType == ‘indexed’) are saved with the colourmap stored in metadata.lutColors (or metadata.colormap). * Time series (T > 1) are saved as separate 3-D stack files or separate 2-D sequence directories, with ‘_T001’, ‘_T002’ suffixes.

USAGE EXAMPLES

%% 1. Lowest level - direct saver use (scripted pipeline)
saver = io.SaverFactory.create('TIF format uncompressed (``*.tif``)');

opts.Format         = 'TIF format uncompressed (``*.tif``)';
opts.Saving3DPolicy = '3D stack';    % or '2D sequence'
opts.Compression    = 'none';        % 'none' | 'lzw' | 'packbits'
opts.showWaitbar    = false;
opts.silent         = true;
opts.overwrite      = true;
opts.FilenameGenerator = 'Use sequential filename';

meta.filename   = 'source_stack.tif';
meta.colorType  = 'grayscale';
meta.lutColors  = [1 1 1];
meta.dataClass  = 'uint16';
meta.maxInt     = 65535;
meta.sliceName  = {};
meta.pixSize    = struct('x',0.065,'y',0.065,'z',0.2,'units','um','t',1,'tunits','s');
meta.imageDescription = '';

data = uint16(rand(512,512,50,1,1) * 65535);  % [H W D C T]
fnOut = saver.save(data, meta, '/output/myStack.tif', opts);
fprintf('Saved: %s\n', fnOut);
%% 2. Via MibImage standalone (without MibModel/MibDataset)
img = core.MibImage(uint8(rand(256,256,30,1,1)*255));
img.filename = '/data/input.tif';

opts.Format         = 'TIF format LZW compression (``*.tif``)';
opts.Saving3DPolicy = '3D stack';
opts.showWaitbar    = false;
opts.silent         = true;
opts.overwrite      = true;
opts.pixSize        = struct('x',1,'y',1,'z',1,'units','um','t',1,'tunits','s');
fnOut = img.save('/output/compressed.tif', opts);
%% 3. Via MibModel (BatchOpt-compatible, recommended for GUI workflows)
BatchOpt.LayerType       = {'image'};
BatchOpt.Format          = {'TIF format uncompressed (``*.tif``)'};
BatchOpt.OutputDirectoryPolicy = {'Full path'};
BatchOpt.DestinationDirectory  = '/output/dir';
BatchOpt.FilenamePolicy  = {'Use existing name'};
BatchOpt.Saving3DPolicy  = {'3D stack'};
BatchOpt.showWaitbar     = false;
BatchOpt.mibBatchTooltip.LayerType = '';   % marks as batch mode
model.save('image', [], BatchOpt);

SEE ALSO io.SaverFactory, io.savers.BaseSaver, io.savers.PngSaver, core.MibImage.save, core.MibDataset.save, models.MibModel.save

Constructor Summary
TiffSaver(options)

TIFFSAVER - Constructor for TiffSaver class.

Syntax:
saver = io.savers.TiffSaver(options)
Input Arguments:
  • options - (optional) struct, saver-level options (usually empty; per-save options are passed to save() instead)

Output Arguments:
  • obj - instance of the TiffSaver class

Method Summary
getSupportedFormats(~)

GETSUPPORTEDFORMATS - Return format strings handled by TiffSaver.

Syntax:
formats = obj.getSupportedFormats()
Input Arguments:

(none)

Output Arguments:
  • formats - cell array of format strings for TIFF output

save(data, metadata, filename, options)

SAVE - Write data as a TIFF file or 2-D TIFF sequence.

Syntax:
fnOut = obj.save(data, metadata, filename, options)

Supports both 3-D multi-frame TIFF (all slices in one file) and 2-D sequence (one file per slice) modes via options.Saving3DPolicy. Time-series data (T > 1) is saved with _T001, _T002 suffixes.

Input Arguments:
  • data - [H, W, D, C, T] numeric array

  • metadata - struct with fields:

    • colorType - 'grayscale' | 'multichannel' | 'indexed'

    • lutColors - (optional) [N × 3] colormap for indexed images

    • colormap - (optional) [N × 3] colormap (alternative to lutColors)

    • sliceName - (optional) cell of char, per-slice source filenames

    • imageDescription - (optional) [char] TIFF ImageDescription tag

    • xResolution - (optional) [numeric] X resolution in pixels/unit; default: 72

    • yResolution - (optional) [numeric] Y resolution in pixels/unit; default: 72

  • filename - [char] full output path, e.g. '/out/stack.tif'

  • options - struct with fields:

    • Format - format string (selects compression mode)

    • Saving3DPolicy - '3D stack' | '2D sequence'; default: '3D stack'

    • showWaitbar - logical; default: true

    • silent - logical, suppress dialogs; default: false

    • overwrite - logical; default: true

    • FilenameGenerator - 'Use original filename' | 'Use sequential filename'

    • Compression - (optional) 'none' | 'lzw' | 'packbits'; overrides Format

Output Arguments:
  • fnOut - [char] for 3D stack single file, or [cell of char] for 2D sequence; [] on failure

Example - see class-level documentation above.

saveStream(provider, metadata, filename, options)

SAVESTREAM - Streaming TIFF writer: one Z-slice from the provider at a time.

Syntax:
fnOut = obj.saveStream(provider, metadata, filename, options)

Memory-bounded twin of save: instead of receiving a full [H W D C T] array it pulls each slice from provider.getSlice(z, t) (an io.savers.SliceProvider) and appends it to the output, so a large pyramid level can be exported without ever holding the whole volume. Honors the same compression / resolution / colormap / 3D-stack vs 2D-sequence options as save.

Input/Output: see io.savers.BaseSaver.saveStream.

Example - stream a BigData image level to a 3-D TIFF stack:

img      = mibModel.I{mibModel.getActiveId()}.image;   % MibBigDataImage
numZ     = img.pyramid.levelImageSizes(1,3);
zScale   = img.pyramid.levelScaleFactors(1,3);
provider = io.savers.MibImageSliceProvider(img,'image',1,[],numZ,img.time,zScale);
saver    = io.savers.TiffSaver(struct());
meta.colorType='grayscale'; meta.dataClass=img.dataClass; meta.imageDescription='';
opts = struct('Saving3DPolicy','3D stack','silent',true,'showWaitbar',false, ...
              'FilenameGenerator','Use sequential filename');
saver.saveStream(provider, meta, 'C:\out\level0.tif', opts);