ImageArithmetics

class controllers.ImageArithmetics

Bases: handle

IMAGEARITHMETICS - Controller for image arithmetic operations in MIB3.

Drives custom arithmetic on one or several open datasets. Available from MIB -> Ribbon -> Image -> Tools for Images -> Image Arithmetics.

obj.startController('ImageArithmetics');                          % GUI mode
obj.startController('ImageArithmetics', [], BatchOpt);            % headless batch
obj.startController('ImageArithmetics', [], NaN);                 % query defaults
Constructor Summary
ImageArithmetics(mibModel, varargin)

IMAGEARITHMETICS - Create and open the Image Arithmetics dialog.

Syntax:
obj = ImageArithmetics(mibModel)
obj = ImageArithmetics(mibModel, extraController)
obj = ImageArithmetics(mibModel, [], BatchOpt)
obj = ImageArithmetics(mibModel, [], NaN)

Supports three operational modes:

  • GUI mode - (mibModel) or (mibModel, extra): creates and shows the AppDesigner dialog.

  • Batch mode - (mibModel, [], BatchOpt): evaluates the expression in BatchOpt.Expression headlessly and returns.

  • Query mode - (mibModel, [], NaN): fires SyncBatch with the default BatchOpt so the Batch controller can read available options.

Input Arguments:
  • mibModel - handle to the MibModel instance

  • varargin - (optional) extra arguments:

    • varargin{1} - extra controller handle (unused, pass [])

    • varargin{2} - BatchOpt struct for batch mode, or NaN for query mode

Output Arguments:
  • obj - handle to the new ImageArithmetics instance

Property Summary
BatchOpt

cell array with handles to listeners

listener

handle to the view (core.ChildView)

mibModel
view

handle to the model

Method Summary
Expression_ValueChangedFcn(hObject)

EXPRESSION_VALUECHANGEDFCN - Sync the Expression textarea value to BatchOpt.

Syntax:
obj.Expression_ValueChangedFcn(hObject)

uitextarea.Value is a cell array of lines; joins them with newlines before storing in obj.BatchOpt.Expression.

Input Arguments:
  • hObject - handle to the Expression uitextarea widget

Output Arguments:

(none)

static ViewListner_Callback2(~, evnt)

VIEWLISTNER_CALLBACK2 - Guard callback: clean up stale listeners if the view was closed.

Syntax:
ImageArithmetics.ViewListner_Callback2(obj, src, evnt)

If the view window is no longer valid (closed before the listener was removed), deletes all listeners and returns silently. Otherwise dispatches to updateWidgets for the relevant events.

Input Arguments:
  • obj - handle to the ImageArithmetics controller instance

  • src - event source (handle to MibModel); ignored

  • evnt - event data; evnt.EventName identifies the event

Output Arguments:

(none)

addCallbacks()

ADDCALLBACKS - Wire all widget callbacks; called once from the constructor.

Syntax:
obj.addCallbacks()

Sets CloseRequestFcn on the figure first, then assigns ValueChangedFcn / ButtonPushedFcn to every interactive widget.

Output Arguments:

(none)

closeWindow()

CLOSEWINDOW - Delete the dialog window and release all listeners.

Syntax:
obj.closeWindow()
Output Arguments:

(none)

helpBtn_Callback()

HELPBTN_CALLBACK - Open the Image Arithmetics help page in a browser.

Syntax:
obj.helpBtn_Callback()
Output Arguments:

(none)

prevExpPopup_Callback()

PREVEXPPOPUP_CALLBACK - Restore a previously used expression from the history dropdown.

Syntax:
obj.prevExpPopup_Callback()

The dropdown displays newline-stripped versions of stored expressions. On selection the matching full expression (with embedded newlines) is retrieved from preferences.ImageArithmetic.Actions and written back to the Expression textarea and the BatchOpt fields.

Output Arguments:

(none)

returnBatchOpt(BatchOptOut)

RETURNBATCHOPT - Return the BatchOpt structure to the Batch controller via the SyncBatch event.

Syntax:
obj.returnBatchOpt()
obj.returnBatchOpt(BatchOptOut)
Input Arguments:
  • BatchOptOut - (optional) local BatchOpt structure generated during the run callback; may contain more fields than obj.BatchOpt. When omitted, obj.BatchOpt is used.

Output Arguments:

(none)

runExpressionBtn_Callback()

RUNEXPRESSIONBTN_CALLBACK - Evaluate the arithmetic expression and write the result.

Syntax:
obj.runExpressionBtn_Callback()

Operates in both GUI and headless batch mode. Steps:

  1. Parse BatchOpt.InputVariables and fetch each dataset via mibModel.getData4D into workspace variables (I, O, M, S, I2, etc.).

  2. Evaluate BatchOpt.Expression with eval and pick up the resulting variable named in BatchOpt.OutputVariables.

  3. Write the result back via mibModel.setData4D. When the target container differs from the source, a new core.MibDataset is created and NewDataset is fired.

  4. Store the expression in preferences.ImageArithmetic history and fire SyncBatch.

Output Arguments:

(none)

Set up progress bar (works in both GUI and headless mode)

updateBatchOptFromGUI(hObject)

UPDATEBATCHOPTFROMGUI - Update obj.BatchOpt from a GUI widget value-change event.

Syntax:
obj.updateBatchOptFromGUI(hObject)

Delegates to utils.updateBatchOptFromGUI_Shared, which is common to all batch-compatible tools.

Input Arguments:
  • hObject - handle to the widget that changed; in AppDesigner callbacks this is the event source (event.Source)

Output Arguments:

(none)

updateWidgets(~)

UPDATEWIDGETS - Refresh dialog widgets from the current model state.

Syntax:
obj.updateWidgets()

This dialog has no model-driven widgets beyond what the constructor populates, so the method is intentionally empty.

Output Arguments:

(none)