# Segmentation

 See :Category:Segmentation for pages about image segmentation.
 Tip: See this helpful workshop on Image Segmentation for another great overview of Segmentation!

# Introduction

Image segmentation is “the process of partitioning a digital image into multiple segments.” (Wikipedia)

It is typically used to locate objects and boundaries.

More precisely, image segmentation is the process of assigning a label to every pixel in an image such that pixels with the same label share certain visual characteristics.

# Easy workflow

One plugin which is designed to be very powerful, yet easy to use for non-experts in image processing:

 Plugin Name Short Description Highlights Plugin Snapshot Trainable Weka Segmentation A tool that combines a collection of machine learning algorithms with a set of selected image features to produce pixel-based segmentations. Can be trained to learn from the user input and perform later the same task in unknown (test) dataMakes use of all the powerful tools and classifiers from the latest version of WekaProvides a labeled result based on the training of a chosen classifierEase of use due to its graphical user interfaces

Give it a try—you might like it!

# Flexible workflow

One good workflow for segmentation in ImageJ is as follows:

1. Preprocess the given images
2. Apply an Auto Threshold
3. Create and manipulate a mask
4. Create and transfer a selection from a mask to your original image
5. Analyze the resulting data

## Preprocessing

Preprocess the image using filters, to make later thresholding more effective. Which filter(s) to use is highly dependent on your data, but some commonly useful filters include:

• Deconvolution
• [https://imagej.net/docs/guide/146-29.html#sub:Subtract-Background… Subtract Background]
• [https://imagej.net/docs/guide/146-29.html#sub:Gaussian-Blur… Gaussian Blur]
• Find Edges

Ideally you want to use one of the auto-threshold methods, rather than manually tweaking, so that your result is reproducible later on the same data, and on multiple other datasets.

• Select Image › Adjust › Threshold…

• Specify whether or not the background should be dark or light
• Adjust the minimum and maximum sliders until you are satisfied with the saturation level of your image

• Select Edit › Selection › Create Mask

• Based on the image and set threshold, some portions of the image may be over/under saturated
• Select the portion of the image that needs to be adjusted
• Select Dilate to grow the included pixels to further saturate this portion of the image or Erode to remove saturation
• One quick way to split overlapping objects is the Watershed command.

## Selections

### Creating Selections

• Select Edit › Selection › Create Selection to select the objects within the mask
• To deselect a portion of the image, select Shift +click

### Transferring Selections

• Before transferring the mask’s selections, revert the image to its original form by selecting Shift +E

• Select first the mask, then the original image, and select Shift +E to transfer the mask’s selections

## Analysis

Do some numerical analysis on the selected data:

• [https://imagej.net/docs/guide/146-30.html#sub:Measure…%5Bm%5D Measure] the entire selection directly.
• Control which measurements are done using [https://imagej.net/docs/guide/146-30.html#sub:Set-Measurements… Set Measurements].
• Use [https://imagej.net/docs/guide/146-30.html#sub:Analyze-Particles… Analyze Particles] to extract desirable objects from your selection and report individual statistics on them.
• Use the ROI Manager to Add the selection and then Split it (under the More button), then use Multi Measure (also under More) to report statistics on the objects.
• Write a macro to automate this sort of analysis, loop over objects in the ROI manager, measure and manipulate them, etc.