ImodContourSaver

class io.savers.ImodContourSaver

Bases: io.savers.BaseSaver

IMODCONTOURSAVER - Saver for IMOD contour model format output (*.mod files).

Handles one format: ‘Contours for IMOD (*.mod)’ - writes an IMOD binary model (.mod) containing one object per segmentation material. Each object holds the contours (closed polygons) extracted from the label volume at each Z-slice.

This saver is labels-only. It is intended for workflows where segmentation results from MIB3 are reviewed, refined, or processed further using IMOD’s 3dmod application.

The saver delegates to the legacy helper mibExportModelToImodModel(), which is ported from MIB2.

DATA DIMENSIONS Input data : [H, W, D, C, T] (MIB3 native order) mibExportModelToImodModel() expects [H, W, D] - squeezed from data.

SAVING OPTIONS PASSED TO mibExportModelToImodModel savingOptions.modelFilename - full output path for the .mod file savingOptions.pixSize - struct {.x .y .z .units .t .tunits} savingOptions.xyScaleFactor - (double) scale factor applied to XY pixel size when building contours; default 5 in silent mode savingOptions.zScaleFactor - (double) scale factor applied to Z spacing; default 1 in silent mode savingOptions.colorList - [M x 3] material RGB colours (0..1) savingOptions.ModelMaterialNames - cell array of material name strings savingOptions.showWaitbar - logical savingOptions.generateSelectionSw - logical, default false in silent mode

USAGE EXAMPLES

%% 1. Export segmentation contours to IMOD .mod file
saver = io.SaverFactory.create('Contours for IMOD (``*.mod``)');

opts.Format         = 'Contours for IMOD (``*.mod``)';
opts.showWaitbar    = false;
opts.silent         = true;
opts.overwrite      = true;
opts.layerType      = 'labels';
opts.xyScaleFactor  = 5;
opts.zScaleFactor   = 1;

meta.filename       = 'source_tomo.tif';
meta.pixSize        = struct('x',0.35,'y',0.35,'z',1.4, ...
                             'units','nm','t',1,'tunits','s');
meta.materialNames  = {'Ribosome'; 'Membrane'; 'Nucleus'};
meta.materialColors = [1 0 0; 0 1 0; 0 0 1];

labels = uint8(rand(512,512,200,1,1)*3);  % [H W D C T]
fnOut = saver.save(labels, meta, '/output/Model_tomo.mod', opts);
fprintf('Saved: %s\n', fnOut);
%% 2. Via MibModel batch - export contours for IMOD annotation review
BatchOpt.LayerType       = {'labels'};
BatchOpt.Format          = {'Contours for IMOD (``*.mod``)'};
BatchOpt.OutputDirectoryPolicy = {'Full path'};
BatchOpt.DestinationDirectory  = '/output/imod';
BatchOpt.FilenamePolicy  = {'Use existing name'};
BatchOpt.showWaitbar     = false;
BatchOpt.mibBatchTooltip.LayerType = '';
model.save('labels', [], BatchOpt);

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

Constructor Summary
ImodContourSaver(options)

IMODCONTOURSAVER - Constructor for ImodContourSaver class.

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

Method Summary
getSupportedFormats(~)

GETSUPPORTEDFORMATS - Return format strings handled by ImodContourSaver.

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

(none)

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

save(data, metadata, filename, options)

SAVE - Write labels data as an IMOD contour model (.mod) file.

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

Only the first channel (C=1) and first time point (T=1) are used.

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

  • metadata - struct with fields:

    • pixSize - struct {.x, .y, .z, .units, .t, .tunits}

    • materialNames - cell array of material name strings

    • materialColors - [M x 3] material RGB colours (0..1)

  • filename - full output path, e.g. '/out/Model_tomo.mod'

  • options - struct with fields:

    • Format - format string

    • layerType - expected 'labels'; warning if not

    • xyScaleFactor - [double] XY contour scale factor; default: 5 in silent mode

    • zScaleFactor - [double] Z scale factor; default: 1

    • generateSelectionSw - [logical] generate selection object; default: false in silent mode

    • showWaitbar - logical; default: true

    • silent - logical, suppress dialogs; default: false

    • overwrite - logical; default: true

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

Example - see class-level documentation above.