Quantification

class controllers.Quantification

Bases: handle

QUANTIFICATION - controller for the Quantification (image statistics) window.

Constructor Summary
Quantification(mibModel, varargin)

QUANTIFICATION - constructor for Quantification controller.

Syntax:
obj = controllers.Quantification(mibModel)
obj = controllers.Quantification(mibModel, mibController, BatchOpt, contIndex)
Input Arguments:
  • mibModel - handle to MibModel

  • varargin{1} - (optional) handle to parent MibController (for startController compatibility)

  • varargin{2} - (optional) BatchOpt struct; pass NaN to return default BatchOpt via SyncBatch

  • varargin{3} - (optional) contIndex - material index to pre-select (-1=Mask, 0=Exterior, 1,2,…=material)

Output Arguments:
  • obj - [Quantification] initialized controller instance

Usage:

Example 1:

obj.startController('controllers.Quantification');
Property Summary
BatchOpt

cell array with class names of initialized child controllers

STATS

cell array of properties to calculate (single or multiple)

anisotropicVoxelsAgree

handle to core.ChildView (views.QuantificationGUI)

availableProperties2D

warning about anisotropic voxels was already shown (1) or not (0)

Type:

flag

availableProperties3D

cell array with the list of available properties for 2D objects

availablePropertiesInt

cell array with the list of available properties for 3D objects

childControllers

struct array with quantification results

childControllersIds

cell array of opened child controller handles

histLimits

cell array with the list of available properties for intensity

indices

limits [low, high] for the histogram display

intType

cell array with handles to event listeners

listener

indices of selected rows in statTable

mibModel
obj2DType

selected mode index for intensity mode

obj3DType

selected mode index for 2D object mode

runId

selected mode index for 3D object mode

sessionSettingsKey

[datasetId, materialId] vector for which STATS were calculated; empty if not yet run

sortingColIndex

‘ascend’ or ‘descend’ - current sort direction

sortingDirection

key into mibModel.sessionSettings used by CropObjects to persist crop/jitter settings

sortingRowIndex

column index used for sorting (1-4)

statProperties

sortingRowIndex(i) -> index in STATS after sorting

Type:

mapping

view

handle to MibModel

Method Summary
static ViewListner_Callback2(src, evnt)

VIEWLISTNER_CALLBACK2 - static listener callback for mibModel events.

Syntax:
obj.ViewListner_Callback2(src, evnt)
Input Arguments:
  • obj - handle to Quantification controller

  • src - event source

  • evnt - event data with EventName field

addCallbacks()

ADDCALLBACKS - Wire all widget callbacks once from the constructor.

Syntax:
obj.addCallbacks()

Called once at the end of the Quantification constructor. Every widget that needs a callback is wired here so the constructor stays clean. Callbacks are set as anonymous functions so MATLAB passes the controller handle implicitly.

Usage:

Example 1:

obj.addCallbacks();   // called inside Quantification constructor
applySelectedProperties(propertyList)

APPLYSELECTEDPROPERTIES - Apply the property list returned by the QuantificationProperties dialog.

Syntax:
obj.applySelectedProperties(propertyList)

Called by the QuantificationProperties child controller when the user confirms the selection. Sorts the list, warns if CurveLength or EndpointsLength requires 8-connectivity, switches Object/Intensity mode if needed, and updates BatchOpt.Property / MultipleProperty.

Input Arguments:
  • propertyList - cell array of selected property names, e.g. {'Area', 'Perimeter', 'MeanIntensity'}

Usage:

Example 1:

obj.applySelectedProperties({'Area', 'Perimeter', 'MeanIntensity'});
closeWindow()

CLOSEWINDOW - Close the Quantification dialog and release all resources.

Syntax:
obj.closeWindow()

Deletes the AppDesigner figure, removes all event listeners, and fires the ‘CloseEvent’ so the parent MibController can purge this child from its childControllers list.

Usage:

Example 1:

obj.closeWindow();  // programmatic close
createContextMenus()

CREATECONTEXTMENUS - Build the right-click context menu for statTable programmatically.

Syntax:
obj.createContextMenus()

Creates a uicontextmenu attached to obj.view.gui and assigns it to the statTable widget. Items cover: selection actions (New/Add/Remove), clipboard copy, annotations (New/Add/Remove), statistics aggregates (Mean/Sum/Min/Max), crop to file/MATLAB, object-to-model conversion, and histogram plotting.

Usage:

Example 1:

obj.createContextMenus();  // called once from addCallbacks
enableStatTable()

ENABLESTATTABLE - Enable or disable statTable depending on whether results are available.

Syntax:
obj.enableStatTable()

for the active dataset.

The table is enabled only when obj.runId(1) matches the currently active dataset index, i.e. results in obj.STATS are current. Called after quantification_Callback completes and on dataset switches.

Usage:

Example 1:

obj.enableStatTable();  // called after quantification_Callback
exportButton_Callback(batchModeSwitch)

EXPORTBUTTON_CALLBACK - Export quantification results to Excel, CSV, MAT file, or MATLAB workspace.

Syntax:
obj.exportButton_Callback()
obj.exportButton_Callback(batchModeSwitch)

In interactive mode (batchModeSwitch = 0) shows a file-save dialog and lets the user choose the format.

Supported formats:
  • Excel (*.xls) via xlswrite2 (in mib/external/)

  • Comma-separated values (*.csv) via writecell / dlmwrite

  • MATLAB struct (*.mat) - full or minimalistic (no PixelIdxList/BoundingBox)

  • Export to MATLAB workspace via assignin

Input Arguments:
  • batchModeSwitch - (optional) logical; 1 = headless batch mode, skips dialogs; default 0

gui_WindowButtonDownFcn()

GUI_WINDOWBUTTONDOWNFCN - Handle mouse button press events on the histogram axes.

Syntax:
obj.gui_WindowButtonDownFcn()

Left-click sets the lower histogram limit (obj.histLimits(1)); right-click sets the upper limit (obj.histLimits(2)). Clicks outside the Y axis range are ignored. After updating the limits the corresponding highlight1/highlight2 edit boxes are updated and objects whose value column falls within [histLimits(1), histLimits(2)] are highlighted in the selection layer.

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

obj.view.gui.WindowButtonDownFcn = @(~,~) obj.gui_WindowButtonDownFcn();
highlightRange_Callback()

HIGHLIGHTRANGE_CALLBACK - Highlight all objects whose Value column falls within the range.

Syntax:
obj.highlightRange_Callback()

specified in the highlight1 and highlight2 edit boxes.

Reads the lower and upper range limits from the highlight1 and highlight2 edit fields, finds all rows in statTable whose Value (column 2) lies within that range, and highlights the corresponding objects in the selection layer. Object IDs are taken from the table RowName, which encodes the canonical object index.

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.highlightRange.ButtonPushedFcn = @(~,~) obj.highlightRange_Callback();
highlightSelection(object_list, mode, sliceNumbers)

HIGHLIGHTSELECTION - Highlight selected quantification objects in the selection layer.

Syntax:
obj.highlightSelection(object_list, mode, sliceNumbers)

Writes to the MIB selection layer for the objects given in object_list. For 2D slice mode or a single object, the selection is written slice-by- slice. For 3D datasets the entire PixelIdxList is written at once.

Input Arguments:
  • object_list - [numeric] vector of object indices into obj.STATS

  • mode (optional) - [char] highlight action (default: read from obj.view.handles.selectionModePanel.SelectedObject.Text):

    • 'Add' - add objects to existing selection

    • 'Remove' - remove objects from existing selection

    • 'Replace' - replace selection with these objects

    • 'obj2model' - assign each object as a separate model material (replaces the current model; shows a confirmation dialog first)

  • sliceNumbers (optional) - [numeric] vector of slice indices, one per object; used to restrict data reading to the relevant slice in 3D datasets

Example 1 - add objects to selection:

obj.highlightSelection([3, 7], 'Add');

Example 2 - replace selection:

obj.highlightSelection(object_list, 'Replace', sliceNums);
histScale_Callback()

HISTSCALE_CALLBACK - Toggle the histogram Y axis between logarithmic and linear scale.

Syntax:
obj.histScale_Callback()

Reads obj.view.handles.logScale checkbox value: true = log, false = linear. Called on checkbox change and after every histogram redraw.

Usage:

Example 1:

obj.histScale_Callback();  // refresh scale after redraw
material_Callback()

MATERIAL_CALLBACK - Handle selection change in the Material dropdown.

Syntax:
obj.material_Callback()

Updates obj.BatchOpt.MaterialIndex and the dialog title bar to reflect the chosen material.

Index encoding:
  • -1 = Mask

  • 0 = Exterior

  • 1, 2, … = individual model materials (modelType ≤ 255)

  • string value = material name (modelType > 255, high-content models)

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.Material.ValueChangedFcn = @(~,~) obj.material_Callback();
multipleBtn_Callback()

MULTIPLEBTN_CALLBACK - Open the property selection dialog for multi-property batch analysis.

Syntax:
obj.multipleBtn_Callback()

Launches the QuantificationProperties child controller which displays checkboxes for all available shape and intensity properties. When the user confirms, the child calls applySelectedProperties to update BatchOpt.MultipleProperty and the Property dropdown.

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.defineProperties.ButtonPushedFcn = @(~,~) obj.multipleBtn_Callback();
multiple_Callback()

MULTIPLE_CALLBACK - Handle the Multiple properties checkbox toggle.

Syntax:
obj.multiple_Callback()

When checked, enables the “Define properties” button (defineProperties) so the user can specify a list of properties for simultaneous calculation. When unchecked, disables defineProperties and syncs BatchOpt.Property from the single-property dropdown.

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.Multiple.ValueChangedFcn = @(~,~) obj.multiple_Callback();
property_Callback()

PROPERTY_CALLBACK - Handle selection change in the Property dropdown.

Syntax:
obj.property_Callback()
Side-effects:
  • Enables ColorChannel2 only when ‘Correlation’ is selected

  • Warns and switches Connectivity to 8 when EndpointsLength/CurveLength is selected with 4/6 connectivity

  • Stores the selected index for the current mode/shape so it can be restored when the user switches shape or mode

  • In Multiple mode, immediately re-sorts and re-renders the table and histogram using the newly chosen display property

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.Property.ValueChangedFcn = @(~,~) obj.property_Callback();
quantification_Callback(batchModeSwitch)

QUANTIFICATION_CALLBACK - Run the shape/intensity quantification analysis and populate statTable.

Syntax:
obj.quantification_Callback()
obj.quantification_Callback(batchModeSwitch)

The main computation engine of the Quantification controller. Dispatches to 3D or 2D code paths depending on BatchOpt.ObjectShape, then iterates over time points and (for 2D) slices. Computed statistics are stored in obj.STATS. After the run, statTable and histogram are updated.

Supported properties (3D): Volume, FilledArea, HolesArea, EndpointsLength, MajorAxisLength, SecondAxisLength, ThirdAxisLength, MeridionalEccentricity, EquatorialEccentricity, ConvexVolume, EquivDiameter, Extent, Solidity, SurfaceArea, Correlation, and all intensity properties.

Supported properties (2D): Area, ConvexArea, CurveLength, Eccentricity, EquivDiameter, EndpointsLength, EulerNumber, Extent, FilledArea, FirstAxisLength, HolesArea, MajorAxisLength, MinorAxisLength, Orientation, Perimeter, SecondAxisLength, Solidity, Correlation, and all intensity properties.

Input Arguments:
  • batchModeSwitch - (optional) logical; 1 = headless batch mode (no GUI updates, no statTable write, auto-exports if configured); default 0

Usage:

Example 1:

obj.quantification_Callback();     // interactive run

Example 2:

obj.quantification_Callback(1);    // batch / scripted run
radioButton_Callback(hObject)

RADIOBUTTON_CALLBACK - Handle Shape2D / Shape3D / Object / Intensity radio button changes.

Syntax:
obj.radioButton_Callback(hObject)

Rebuilds the Property dropdown items appropriate for the new mode/shape combination and restores the last-used property index for that mode.

Additionally:
  • Switching to Shape2D resets Property to ‘Area’ and clears Multiple

  • Switching to Shape3D resets Property to ‘Volume’, clears Multiple, and refreshes the Units warning for anisotropic voxels

  • Switching Object/Intensity toggles ColorChannel1 visibility

Input Arguments:
  • hObject - handle to the radio button widget that fired the callback; Tag is used to distinguish Shape2D/Shape3D from Object/Intensity

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.Shape2D.ValueChangedFcn = @(hObj,~) obj.radioButton_Callback(hObj);
returnBatchOpt(BatchOptOut)

RETURNBATCHOPT - Publish BatchOpt to the macro recorder via ‘SyncBatch’ event.

Syntax:
obj.returnBatchOpt()
obj.returnBatchOpt(BatchOptOut)

Fires a SyncBatch event carrying the current (or provided) BatchOpt so that the MIB batch controller can record this action.

Input Arguments:
  • BatchOptOut - (optional) struct with Batch Options to publish; defaults to obj.BatchOpt

Usage:

Example 1:

obj.returnBatchOpt();                  // publish current BatchOpt

Example 2:

obj.returnBatchOpt(myCustomBatchOpt);  // publish custom BatchOpt
sortBtn_Callback(data)

SORTBTN_CALLBACK - Sort the statTable data matrix according to the current sorting settings.

Syntax:
data = obj.sortBtn_Callback()
data = obj.sortBtn_Callback(data)

Reads obj.sortingColIndex and obj.sortingDirection (set by updateSortingSettings) and reorders rows accordingly. When called with no data argument it reads from and writes back to the table widget.

Input Arguments:
  • data - (optional) numeric matrix [N×4] with table contents (cols: ObjId, Value, Slice, TimePnt); when omitted the current statTable.Data is used and the result is written back to the table

Output Arguments:
  • data - sorted numeric matrix [N×4]

Usage:

Example 1:

data = obj.sortBtn_Callback(data);   // sort supplied matrix

Example 2:

obj.sortBtn_Callback();              // sort and refresh table in-place
statTable_CellSelectionCallback(indices, parameter)

STATTABLE_CELLSELECTIONCALLBACK - Handle cell selection in statTable and optionally highlight objects.

Syntax:
obj.statTable_CellSelectionCallback(indices, parameter)

Called both from the table’s CellSelectionCallback and from context menu items. Navigates to the slice containing the selected object and, depending on parameter, highlights it in the selection layer.

Input Arguments:
  • indices - numeric [N×2] array of [row, col] indices of selected cells, as provided by AppDesigner CellSelectionCallback evnt.Indices; pass [] to use the last saved selection (obj.indices)

  • parameter - string controlling highlight behaviour - ‘skip’ - navigate to slice but only highlight if highlightOnClick is on; Ctrl+click forces ‘Remove’ - ‘Add’ - add selected objects to selection layer - ‘Remove’ - remove selected objects from selection layer - ‘Replace’ - replace selection layer with selected objects - ‘obj2model’ - convert each selected object to a new model material

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.statTable.CellSelectionCallback = @(~,evnt) obj.statTable_CellSelectionCallback(evnt.Indices, 'skip');

Example 3:

obj.statTable_CellSelectionCallback([], 'Replace');  // from context menu
tableContextMenu_cb(parameter)

TABLECONTEXTMENU_CB - Handle context menu actions on statTable rows.

Syntax:
obj.tableContextMenu_cb(parameter)

Dispatches to the appropriate action based on parameter. All actions operate on the rows currently selected in obj.indices.

Input Arguments:
  • parameter - [char] action identifier:

    • 'mean' - compute mean of column 2 for selected rows; copy to clipboard

    • 'sum' - compute sum; copy to clipboard

    • 'min' - compute min; copy to clipboard

    • 'max' - compute max; copy to clipboard

    • 'copyColumn' - copy selected column(s) to system clipboard

    • 'crop' - open controllers.CropObjects with centroids of selected objects

    • 'hist' - plot histogram of selected values in the histogram axes

    • 'newLabel' - create new MIB annotations at selected object centroids

    • 'addLabel' - add MIB annotations (keeps existing)

    • 'removeLabel' - remove MIB annotations at selected centroids

Example 1 - compute and copy mean value:

obj.tableContextMenu_cb('mean');

Example 2 - open crop dialog:

obj.tableContextMenu_cb('crop');
units_Callback()

UNITS_CALLBACK - Handle selection change in the Units dropdown.

Syntax:
obj.units_Callback()

Warns the user when switching to physical units in 3D mode with anisotropic voxels (x≠z or y≠z), because several 3D measurements (MajorAxisLength, SurfaceArea, EquivDiameter, eccentricities) are only geometrically valid for isotropic voxels. The warning is shown once per session (obj.anisotropicVoxelsAgree flag).

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.Units.ValueChangedFcn = @(~,~) obj.units_Callback();
updateBatchOptFromGUI(hObject, ~)

UPDATEBATCHOPTFROMGUI - Sync BatchOpt from a changed widget using the shared utility.

Syntax:
obj.updateBatchOptFromGUI(hObject)

Delegates to utils.updateBatchOptFromGUI_Shared which reads the widget’s Tag and Value and writes the matching BatchOpt field. The second event argument (~) is accepted but ignored for AppDesigner compatibility.

Input Arguments:
  • hObject - handle to the AppDesigner widget whose value changed ~: ignored ValueChangedData argument (AppDesigner passes it automatically)

Usage:

Example 1:

% wired in addCallbacks for multiple widgets:

Example 2:

h.DatasetType.ValueChangedFcn = @(hObj,~) obj.updateBatchOptFromGUI(hObj);
updateSortingSettings()

UPDATESORTINGSETTINGS - Sync sort direction and column index from the sortTable dropdown.

Syntax:
obj.updateSortingSettings()

Reads the selected item from sortTable (e.g. ‘Value, descend’), updates obj.sortingDirection (‘ascend’/’descend’) and obj.sortingColIndex (1=ObjId, 2=Value, 3=Slice, 4=TimePnt, 5=RowIndex), then immediately re-sorts the table.

Usage:

Example 1:

% wired in addCallbacks:

Example 2:

h.sortTable.ValueChangedFcn = @(~,~) obj.updateSortingSettings();
updateWidgets()

UPDATEWIDGETS - Refresh all GUI widgets from the current model state and BatchOpt.

Syntax:
obj.updateWidgets()

Called at startup (after the view is created) and whenever the active dataset changes.

Repopulates:
  • Material dropdown - Mask, Exterior, and all model materials

  • ColorChannel1/ColorChannel2 dropdowns

  • DatasetType, ObjectShape, DetectionType, Property, Connectivity, Units dropdowns

  • Multiple checkbox and MultipleProperty string

  • Sorting popup

  • Slice/time-point slider state

  • statTable enable/disable state via enableStatTable

Usage:

Example 1:

obj.updateWidgets();  // full refresh, e.g. on dataset change