======================= Cell/stalk segmentation ======================= .. container:: note BacStalk is not a tool for segmentation of cells in images with high cell densities (i.e. many cells that touch eachother). We reccomend to take your images at lower cell densities. Alternatively, you can use the software tools `MicrobeJ `_ or `Oufti `_. Or, in case of bacterial communities, `BiofilmQ `_. The cell/stalk segmentation view provides tools for cell detection, cell tracking, visualization and object manipulation. Each image is only loaded once it is requested to save memory. .. image:: ../images/segmentation.png :alt: Segmentation view :width: 100 % :align: center A typical workflow involves: 1. Define a region of interest (**ROI**) by clicking :guilabel:`Set` at the upper left in the panel :guilabel:`Parameters`. A draggable and resizeable rectangle appears, whose coordinates are stored in the ROI-field. - To *unselect* the ROI click somewhere in the image with no specific cursor (panning or zooming) selected. - To *remove* the ROI, click :guilabel:`Clear`. - To *modify* an existing unselected ROI, either click :guilabel:`Set` again or click on the border of the ROI rectangle to make it editable again. - To *apply the ROI to all images loaded*, click :guilabel:`Apply to all`. 2. Setup the `Segmentation parameters`_ - Adapt the parameter :guilabel:`Cell size` to the diameter of typical cell in the images. - Use :menuselection:`Tools --> Measure distance` to display an interactive ruler. - Change the other parameters as needed. 3. Click :guilabel:`Process image` to process the current image or :guilabel:`Process all images` to process the entire data set. - The progress can be monitored with the progress bar. - The style of the segmented cells can be changed at `Display parameters`_. - For more details regarding the stalk detection algorithm see `Stalk detection algorithm`_ .. container:: note If the *Parallel Computing Toolbox* is available and :guilabel:`Parallel processing` is enabled at :menuselection:`Parameters --> Other`, as many images are processed in parallel as many workers are set up in the toolbox preferences. Parallel processing greatly reduces the required processing time. .. container:: caution If an image is reprocessed, the current segmentation result (including manual edits) will be lost! 4. Click :guilabel:`Track cells` to track cells among all processed frames (see `Cell tracking parameters`_). 5. Clicking on an entry in the :guilabel:`Cell list`, *zooms in* on and *highlights* the selected cell. - Deselect the :guilabel:`Zoom` or :guilabel:`Pan` tool to display a normal mouse pointer for *cell/stalk manipulation*. - To *delete a cell*, either click on the cell outline, the number displayed next to the cell or check :code:`CellDeleted` in the cell list. This will change the color of the cell outline and line style to *dashed* - -. - To *remove a stalk*, click on the stalk in the image. This will change the stalk color and line style to *dashed* - -. - To *undo a deletion*, click on the dashed line to revert the last operation. - To *reverse the orientation of a medial axis*, click on the medial axis or on the circular marker indicating the pole (set to broadest by default). .. container:: caution If a cell/stalk is manually deleted, the analysis table in the :guilabel:`Analysis`-view is not automatically updated. Please press the :guilabel:`Refresh` button above the table. 6. By clicking on an entry in the :guilabel:`Track list` the cell with the selected :code:`TrackID` in the last frame of the corresponding trajectory is displayed and the trajectory is overlayed. Parameters ========== Segmentation parameters ----------------------- - :guilabel:`Cell size`: Typical cell size in pixels. Prior to cell segmentation, the images are enhanced by bandpass-filtering. :code:`Cell size` defines the size of the filter kernel. - :guilabel:`Min cell size`: Minimum cell size in pixels. Cells below this size threshold are automatically marked as :code:`CellDeleted=1` and can be included by clicking on them or deselect :code:`CellDeleted` in the :guilabel:`Cell list`. The following parameters are only available if My cells... :guilabel:`... have stalks` is checked in the image input tab (see :ref:`Image input`). - :guilabel:`Cell expansion width`: Prior to stalk detection, cells are expanded (dilated) by the indicated number of pixels to search for the stalk attachment point. If the cells are surrounded by a bright ring, increasing this value might increase the stalk detection frequency. - :guilabel:`Stalk screening length`: Maximum stalk search length in pixels. - :guilabel:`Min stalk length`: Minimum stalk length in pixels. Stalks below this length threshold are ignored. - :guilabel:`Max stalk flexibility`: Maximum stalk flexibility. Stalks with flexibility above this value are ignored. The flexibility is defined as :code:`stalk contour length` / :code:`stalk end-to-end distance`. Hence, a straight stalk has a flexibility of :code:`1`. - :guilabel:`Stalk screening width`: Step size for stalk propagation in pixels. A higher values reduces the stalk contour resolution but increases the tolerance for gaps in the stalk signal. - :guilabel:`Stalk sensitivity`: Stalk detection sensitivity, based on the intensity difference between the pixels belonging to the stalk and pixels in the background. Low values increase the probability for false detections. - :guilabel:`Exclude cells close by`: If checked, cells which are closer together than :code:`Cell expansion width` are marked as :code:`CellDeleted=1`. Cell tracking parameters ------------------------ - :guilabel:`Search radius`: Cells are tracked by comparing the spatial overlap along consecutive frames. To avoid calculating the overlap between all cells an to therefore speed up the tracking process, only neighboring cells within the :code:`Search radius` are considered. - :guilabel:`Dilation width`: Prior to determining the spatial overlap, cells can be enlarged. If cells are moving, it can help to increase this value if otherwise no overlap is present in considered frames. Display parameters ------------------ - :guilabel:`Overlay font size`: Font size (in points) of overlay text in the image display. - :guilabel:`Line width`: Line width (in points) of cell outlines and stalks. - :guilabel:`Plot resolution`: Plotting resolution of cell outlines and stalks. - :guilabel:`Show trackID`: Displays the :code:`TrackID` of each cell next to the :code:`CellID`. Advanced parameters ------------------- - :guilabel:`Parallel processing`: Use multiple CPU-cores for parallel image processing (requires the Matlab *Parallel Computing Toolbox*). The number of workers is set up in the preferences of the *Parallel Computing Toolbox*. - :guilabel:`Debugging`: Output debugging information during cell/stalk segmentation (requires :code:`Parallel processing=0`). - :guilabel:`Cell channel`: Input channel including the cell images. - :guilabel:`Use binary masks`: Check if images contain pre-segmented binary masks by 3rd-party software. - :guilabel:`Image background`: Select the image background type (usually 'bright' for phase contrast images and 'dark' for fluorescence images). - :guilabel:`Stalk channel`: Input channel including the stalk images. If the cells are imaged in phase contrast usually the stalks are present in the same channel as the cells. This option might be useful if cells and stalks where labelled with different fluorescent probes. Stalk detection algorithm ========================= The general principle of the stalk detection algorithm is illustrated in the Figure below. .. image:: ../images/stalkDetection.png :alt: Stalk detection algorithm :width: 100 % :align: center - (\1) The cell of interest is expanded by the amount of pixels set in :code:`Cell expansion width` to generate the shell shown in magenta. - (\2) The intensity profile along the shell generated in (1) is measured. The pixel of lowest intensity which is below the Z-score (dependent on the value set for the :code:`Stalk sensitivity`), is considered to be the attachment point of a stalk. - (\3-6) The stalk is propagated by dilating the stalk attachment point by the set :code:`Stalk screening width`. Previously processed regions are excluded from the dilation result and the intensity values of the remaining pixels are analyzed. The pixel of lowest intensity is added to the stalk backbone (if its intensity is below the Z-score (of value :code:`Stalk sensitivity`); if not, the stalk ends). - (\7) If the stalk hits a pixel of another cell, both cells are linked to each other and the cell with the largest area is flagged as "mother cell" and the other cell as "bud".