Skip to content

Auto Segmentation

mattmac22 edited this page Aug 15, 2014 · 8 revisions

Introduction

Workflow

  1. Navigate to the directory that contains your image files.
  2. Launch the GUI
segment.SegmentGUI();
  1. Select the desired auto-segmentation algorithm from the drop-down list.
  2. Select desired options in "ALGORITHM_NAME Options".
  3. Press "Auto Segment" button.
  4. If settings are acceptable, select "Run On All Images" button
  5. Use Next and Previous buttons to navigate between images and view the segmentation results. Edit the results by toggling between the "Delete" and "Segment" modes.

UI Controls

Top Panel

  • "Image # of #" TextView Position in directory's images

  • Previous/Next Navigate between images. Next button causes that image's data files to be overwritten. The segmentations displayed are saved. Previous button loads the segmentations from runtime memory. SegmentGUI never loads from data files.

** Algorithm Panel **

  • Algorithm Drop-Down Select which algorithm is used when auto-segmenting. The options contained in the "Algorithm Options" panel will change when a different algorithm is selected.

  • Auto Segment The algorithm is run on the current image.

  • Delete/Segment Toggle click mode. Delete mode allows you to delete segmentations by simply clicking within the segmentation boundary. Segment mode allows you to draw new segmentations using your cursor.

Display Options Panel

  • Show Nuclei Toggle nuclei overlay

** Algorithm Options Panel**

  • Subtract Median Median image intensity is subtracted from the image before running the auto-segmentation algorithm.

  • Slider - Gray Watershed A factor multiplied by the result returned by graythresh function when converting to a binary image. Full context:

bw = im2bw(img, factor * graythresh(img));

Adding New Algorithms

Add To Popup: Next, add the option to the popup menu. Open the createAndLayoutMainGUI script:

edit segment.createAndLayoutMainGUI

Find, the following segment of code:

Hs.algorithmMenu = uicontrol('Style','popupmenu',...
        'Units','normalized',...
        'Parent', Hs.editPanel,...
        'String',{'Trivial Division','Canny Watershed', 'Gray Watershed'},...
        'Position',[0.45, 0.68, 0.50, 0.27]);

Add 'Magic' to the end of the 'String' cell array.

Add Case in SegmentManager:

Find the switch statement in the segmentImage(p) function and add the following case to the switch statement:

case 'Magic'
    pixelList = segment.segmenters.cannyWatershed.segmentImage(imageSet('dapi'), imageSet(channelToSegment), OPTIONS);

Add Package: Let's say you wanted to create an auto-segmentation algorithm called "Magic". First, create a +magic package whose path is given by:

~/rajlab/imageProcessing/+segment/+segmenters/+magic

Add Segment Script: Add segmentImage(dapiImage, chanImage, OPTIONS) script to the +magic package.

function pixelList = segmentImage(dapiStack, chanStack, OPTIONS)
    Segmentation code
end

pixelList is a cell array of matrices where each matrix contains a list of indices belonging to a single image. For example, let's say that the matrix below is a binary image where 1's represent cells and 0's represent the background.

1  1  0  0  0
1  1  0  1  1
0  0  0  1  1
0  0  0  0  0
0  0  0  0  0

The resulting pixelList would be {[1, 2, 6, 7], [17, 18, 22, 23]}

Add Algorithm Specific Options: First add a function addMagicOptions(optionsLayout) to the following directory:

~/rajlab/imageProcessing/+segment/+optionViews/

This is for UIControls such as checkboxes or sliders. It should return a structure with handles to the UI elements. See other functions in the +optionViews package for examples.

Next, edit the OptionsManager so that these UIControls can be interpreted. OptionsManager is located at:

rajlab/imageProcessing/+segment/OptionsManager

In the setOptionsByAlgorithmName(p, algorithmName) function add a case to the switch statement:

case 'Magic'
    p.VIEWS = segment.optionViews.addMagicOptions(p.optionsLayout);

Then, add a case to the getOptions(p) function's switch statement. The OPTIONS structure contains data that will be passed to the segmentation algorithm. For example, if you had one checkbox in the Algorithm Options panel called subtractMedianCheckkBox, then the code might look like the following:

case 'Magic'
    OPTIONS.subtractMedian = get(p.VIEWS.subtractMedianCheckBox, 'Value');