Graphcut

class controllers.Graphcut

Bases: handle

GRAPHCUT - Controller for graph-cut (max-flow/min-cut) image segmentation.

Provides 2D-per-slice, 2D-all-slices, 3D, and 3D-grid segmentation modes using SLIC or Watershed supervoxels combined with maxflow/mincut optimization. Available from MIB → Ribbon → Segmentation → Graphcut.

Constructor Summary
Graphcut(mibModel)

GRAPHCUT - Constructor; creates and shows the Graphcut segmentation window.

Syntax:
controller = controllers.Graphcut(mibModel)
Input Arguments:
  • mibModel - handle to the MibModel instance

Output Arguments:
  • controller - handle to the constructed Graphcut object

Property Summary
graphcut

cell array with handles to event listeners

graphcutVersion

struct array with graphcut data: .slic - superpixel/supervoxel label array .noPix - number of superpixels/supervoxels .Graph - cell of sparse adjacency graphs for maxflow .Edges - cell of edge lists [src dst] .EdgesValues - cell of edge intensity differences .PixelIdxList - (optional) pixel index lists per superpixel .bb - bounding box [x1 x2 y1 y2 z1 z2] .grid - struct with grid tile bounding boxes (mode3dGridRadio) .version - graphcut format version (2.2) .mode - segmentation mode string .binVal - binning factors [xy z] .colCh - color channel index .spSize - superpixel size parameter .spCompact - SLIC compactness parameter .superPixType - ‘SLIC’ or ‘Watershed’ .blackOnWhite - signal polarity flag .scaleFactor - edge weight scaling factor .dilateMode - ‘pre’ or ‘post’ dilation mode .tilesX/Y/Z - grid tile counts

listener

handle to the view (core.ChildView wrapping views.GraphcutGUI)

mibGUI

handle to MibModel

mibModel
mode

version of the graphcut structure

realtimeSwitch

active segmentation mode string: ‘mode2dCurrentRadio’ | ‘mode2dRadio’ | ‘mode3dRadio’ | ‘mode3dGridRadio’

seedBg

object seeds per slice (3D modes)

Type:

cell array

seedObj

label vectors of currently displayed superpixels

Type:

cell array

shownLabelObj

size parameter for Watershed superpixels

slicSize

enable real-time segmentation on model paint

Type:

logical

timerElapsed

background seeds per slice (3D modes)

Type:

cell array

timerElapsedMax

elapsed time of last segmentation (seconds); controls waitbar display

view

shortcut to mibModel.mibGUI (parent figure for dialogs)

watershedSize

size parameter for SLIC superpixels

Method Summary
static ViewListner_Callback2(~, evnt)

VIEWLISTNER_CALLBACK2 - React to model events; clean up listeners if the view is gone.

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

  • evnt - event data; evnt.EventName is inspected for dispatch

addCallbacks()

ADDCALLBACKS - Wire all GUI widget callbacks to controller methods.

binSubareaEdit_Callback(hObject)

BINSUBAREAEDIT_CALLBACK - Parse and normalise the binning field value.

Syntax:
obj.binSubareaEdit_Callback(hObject)
Input Arguments:
  • hObject - handle to binSubareaEdit; .Value is a semicolon-separated pair of integers, e.g. '2; 1' (XY bin; Z bin)

calcSupervoxels(Graphcut, img, parLoopOptions, usePrecomputedSlic)

CALCSUPERVOXELS - Generate 3D supervoxels and build the boundary graph for graph-cut.

Syntax:
Graphcut = controllers.Graphcut.calcSupervoxels(Graphcut, img, parLoopOptions)
Graphcut = controllers.Graphcut.calcSupervoxels(Graphcut, img, parLoopOptions, usePrecomputedSlic)
[Graphcut, cancelled] = controllers.Graphcut.calcSupervoxels(Graphcut, img, parLoopOptions, usePrecomputedSlic)
Input Arguments:
  • Graphcut - struct with graphcut data (fields modified by this function):

    • .slic - label array (read when usePrecomputedSlic=1, written otherwise)

    • .noPix - number of supervoxels (written)

    • .Edges - cell of [N×2] adjacency edge lists (written)

    • .EdgesValues - cell of [N×1] mean-intensity differences per edge (written)

    • .dilateMode - 'pre' or 'post'; set by Watershed path

  • img - [uint8 | uint16] 3-D image array [height × width × depth]

  • parLoopOptions - struct with processing options:

    • .binVal - [1×2 numeric] [xyBin, zBin] binning factors

    • .binHeight - [numeric] pre-calculated binned height

    • .binWidth - [numeric] pre-calculated binned width

    • .binDepth - [numeric] pre-calculated binned depth

    • .waitbar - uiprogressdlg handle or [] to skip progress updates

    • .cancelProgressBar - uiprogressdlg handle or []; checked at phase boundaries so the user can cancel without disrupting the progress display

    • .viewPort - struct with .min, .max, .gamma for contrast mapping

    • .onFlyImageStretch - [logical] use auto-stretch instead of viewPort limits

    • .superPixType - [char] 'SLIC' or 'Watershed'

    • .blackOnWhite - [logical] invert image before watershed

    • .superpixelSize - [numeric] target supervoxel volume (SLIC) or h-minima depth (Watershed)

    • .superpixelCompact - [numeric] SLIC compactness parameter

    • .tilesX - [numeric] number of SLIC tiles in X

    • .tilesY - [numeric] number of SLIC tiles in Y

  • usePrecomputedSlic (optional) - [logical] when 1, skip supervoxel calculation and use Graphcut.slic as-is; default: 0

Output Arguments:
  • Graphcut - updated struct with .slic, .noPix, .Edges, .EdgesValues, and (Watershed only) .dilateMode populated

  • cancelled (optional) - [logical] true when the user cancelled via parLoopOptions.cancelProgressBar; the caller must detect this and clean up

checkDimensions(hObject)

CHECKDIMENSIONS - Validate a dimension edit field value and clear preprocessed data.

Syntax:
obj.checkDimensions(hObject)
Input Arguments:
  • hObject - handle to xSubareaEdit, ySubareaEdit, or zSubareaEdit

clearPreprocessBtn_Callback()

CLEARPREPROCESSBTN_CALLBACK - Reset the graphcut struct and update bounding-box from UI.

Syntax:
obj.clearPreprocessBtn_Callback()
status = obj.clearPreprocessBtn_Callback()
Output Arguments:
  • status - [logical] 1 when cleared successfully, 0 when cancelled

closeWindow()

CLOSEWINDOW - Delete the view and all listeners, then fire CloseEvent.

currentViewBtn_Callback()

CURRENTVIEWBTN_CALLBACK - Set the XY sub-area from the currently visible image region.

doGraphcutSegmentation()

DOGRAPHCUTSEGMENTATION - Run maxflow/mincut and write the result to the mask layer.

Reads object/background seeds from the labels layer, builds the data term, calls maxflow_v222, and writes the resulting mask - either incrementally (when shownLabelObj is already set) or in full.

exportSuperpixelsBtn_Callback()

EXPORTSUPERPIXELSBTN_CALLBACK - Export the graphcut struct to workspace, file, model, or 3D lines.

importSuperpixelsBtn_Callback(noImportSwitch)

IMPORTSUPERPIXELSBTN_CALLBACK - Load a saved graphcut struct or pre-computed clusters.

Syntax:
obj.importSuperpixelsBtn_Callback()
obj.importSuperpixelsBtn_Callback(noImportSwitch)
Input Arguments:
  • noImportSwitch (optional) - [logical] when 1, restore the UI from the current obj.graphcut without showing the import dialog; default: 0

mode2dRadio_Callback(hObject)

MODE2DRADIO_CALLBACK - Handle segmentation mode change from the radio button group.

Syntax:
obj.mode2dRadio_Callback(hObject)
Input Arguments:
  • hObject - handle to the newly selected radio button

parforCheck_Callback()

PARFORCHECK_CALLBACK - Start a parallel pool when the parallel checkbox is ticked.

pixelIdxListCheck_Callback()

PIXELIDXLISTCHECK_CALLBACK - Compute or remove PixelIdxList from the graphcut struct.

When ticked, calls regionprops for each graphcut element and stores PixelIdxList to accelerate incremental mask updates during segmentation.

realtimeCheck_Callback(hObject)

REALTIMECHECK_CALLBACK - Sync realtimeSwitch with the checkbox state.

Syntax:
obj.realtimeCheck_Callback(hObject)
Input Arguments:
  • hObject - handle to realtimeCheck

recalcGraph_Callback(showWaitbar)

RECALCGRAPH_CALLBACK - Rebuild the sparse boundary graph from stored edges and scale factor.

Syntax:
obj.recalcGraph_Callback()
obj.recalcGraph_Callback(showWaitbar)
Input Arguments:
  • showWaitbar (optional) - [logical] show a progress dialog; default: 0

resetDimsBtn_Callback()

RESETDIMSBTN_CALLBACK - Reset sub-area edit fields to the full dataset extent.

segmentAllBtn_Callback()

SEGMENTALLBTN_CALLBACK - Segment every grid tile sequentially and show the result.

segmentBtn_Callback()

SEGMENTBTN_CALLBACK - Back up the mask, run one segmentation pass, and show the result.

subAreaFromSelectionBtn_Callback()

SUBAREAFROMBTN_CALLBACK - Set the sub-area from the bounding box of the selection layer.

superpixTypePopup_Callback(parameter)

SUPERPIXTYPE_CALLBACK - Update UI controls when the superpixel type changes.

Syntax:
obj.superpixTypePopup_Callback()
obj.superpixTypePopup_Callback(parameter)
Input Arguments:
  • parameter (optional) - [char] pass 'keep' to suppress clearing the preprocessed data after UI update; default: 'clear'

superpixelsBtn_Callback(usePrecomputedSlic)

SUPERPIXELSBTN_CALLBACK - Compute supervoxels and the boundary graph for all modes.

Syntax:
obj.superpixelsBtn_Callback()
obj.superpixelsBtn_Callback(usePrecomputedSlic)
Input Arguments:
  • usePrecomputedSlic (optional) - [logical] when 1, skip supervoxel calculation and rebuild the graph from the existing obj.graphcut.slic; default: 0

superpixelsPreviewBtn_Callback()

SUPERPIXELSPREVIEWBTN_CALLBACK - Show supervoxel boundaries in the selection layer.

updateMaterialsBtn_Callback()

UPDATEMATERIALSBTN_CALLBACK - Repopulate background/signal material dropdowns.

updateWidgets()

UPDATEWIDGETS - Refresh all widget states from the current dataset.