MrcSaver

class io.savers.MrcSaver

Bases: io.savers.BaseSaver

MRCSAVER - Saver for MRC format output (used by IMOD and related EM tools).

Handles two format variants (both write the same MRC file; the second is an alias used in the SaverFactory registry for volume export): ‘MRC format for IMOD (*.mrc)’ - standard MRC file for IMOD ‘MRC Volume for IMOD (*.mrc)’ - alias, same output format

Both image and label/mask volumes can be saved. The layer type is controlled by options.layerType (default ‘image’).

IMPORTANT: MRC supports only single-channel data (C=1). If the input data has more than one colour channel a warning is issued and only the first channel is written.

The saver delegates the actual I/O to the legacy helper mibImage2mrc(), which is ported from MIB2.

DATA DIMENSIONS Input data : [H, W, D, C, T] (MIB3 native order) mibImage2mrc() expects [H, W, D] - obtained by squeezing C=1, T=1.

FILENAME GENERATOR options.FilenameGenerator controls how the output file is named: ‘Use sequential filename’ (default) - numbered naming ‘Use original filename’ - derived from metadata.sliceName

TODO: port mibImage2mrc from MIB2_RENAMED_FOR_MIB3/ImportExportTools/mibImage2mrc.m to mib/+io/mibImage2mrc.m

USAGE EXAMPLES

%% 1. Save EM tomogram as MRC for IMOD
saver = io.SaverFactory.create('MRC format for IMOD (``*.mrc``)');

opts.Format            = 'MRC format for IMOD (``*.mrc``)';
opts.showWaitbar       = false;
opts.silent            = true;
opts.overwrite         = true;
opts.layerType         = 'image';
opts.FilenameGenerator = 'Use sequential filename';

meta.filename  = 'source_tomo.tif';
meta.colorType = 'grayscale';
meta.dataClass = 'uint8';
meta.maxInt    = 255;
meta.pixSize   = struct('x',0.35,'y',0.35,'z',1.4, ...
                        'units','nm','t',1,'tunits','s');

data = uint8(rand(512,512,200,1,1)*255);  % [H W D C T]
fnOut = saver.save(data, meta, '/output/myTomo.mrc', opts);
fprintf('Saved: %s\n', fnOut);
%% 2. Save segmentation labels volume for IMOD
saver = io.SaverFactory.create('MRC Volume for IMOD (``*.mrc``)');

opts.Format      = 'MRC Volume for IMOD (``*.mrc``)';
opts.showWaitbar = false;
opts.silent      = true;
opts.overwrite   = true;
opts.layerType   = 'labels';

meta.filename  = 'source_tomo.tif';
meta.pixSize   = struct('x',0.35,'y',0.35,'z',1.4, ...
                        'units','nm','t',1,'tunits','s');

labels = uint8(rand(512,512,200,1,1)*3);  % [H W D C T]
fnOut = saver.save(labels, meta, '/output/Labels_myTomo.mrc', opts);

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

Constructor Summary
MrcSaver(options)

MRCSAVER - Constructor for MrcSaver class.

Syntax:
saver = io.savers.MrcSaver(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 MrcSaver class

Method Summary
getSupportedFormats(~)

GETSUPPORTEDFORMATS - Return format strings handled by MrcSaver.

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

(none)

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

save(data, metadata, filename, options)

SAVE - Write data as an MRC file for IMOD.

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

MRC supports only single-channel data (C=1); a warning is issued and only the first channel is written if C>1.

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

  • metadata - struct with fields:

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

    • dataClass - 'uint8' | 'uint16' | …

    • maxInt - maximum intensity value

    • pixSize - struct {.x, .y, .z, .units, .t, .tunits}; used for MRC cell/voxel size header

  • filename - full output path, e.g. '/out/tomo.mrc'

  • options - struct with fields:

    • Format - format string

    • layerType - 'image' | 'mask' | 'labels'; default: 'image'

    • showWaitbar - logical; default: true

    • silent - logical, suppress dialogs; default: false

    • overwrite - logical; default: true

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

Output Arguments:
  • fnOut - [char] path of saved .mrc file, [] on failure

Example - see class-level documentation above.