Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For automatic oversegmentation, start with skimage.segmentation.felzenszwalb. To group or split already-labeled regions, build a region adjacency graph (RAG) and use a graph operation such as normalized cut or threshold merging. If you can supply seed labels, watershed and random walker are marker-guided alternatives. These approaches work at different levels, so the right choice depends on whether you need initial regions, region-level grouping, or labels guided by markers.

What graph-based segmentation means in practice

Image segmentation assigns a label to each pixel so that pixels in the same label form a region. In graph-based workflows, the graph may represent the image grid itself or a smaller set of regions created by an initial segmentation.

  • Image-grid segmentation: an algorithm groups pixels directly. Felzenszwalb’s method produces labels this way.
  • Region-level graph: an initial segmentation supplies labeled regions, which become nodes in a region adjacency graph. Edges encode relationships such as color similarity or boundary evidence; a later operation merges or partitions those regions.
  • Marker-guided labeling: user- or algorithm-supplied seeds guide the assignment of pixels, as in random walker and watershed.

These are related tools, not interchangeable implementations of one task. The scikit-image 0.26.0 graph API documents RAG construction and operations, while its segmentation API documents Felzenszwalb, random walker, and watershed: skimage.graph API and skimage.segmentation API.

Choose the method that matches the job

Method Input and graph level Useful when Main controls and cautions
Felzenszwalb Image-grid graph; no user markers required You need automatic, often fine-grained initial regions. scale sets the observation level; higher values generally produce fewer, larger regions. sigma smooths the image, and min_size affects small components. Resulting segment sizes can vary with local contrast.
Normalized cut Similarity RAG built from existing labels You want to recursively divide an oversegmentation into larger groups. Edge meaning and scale affect the result. thresh controls when recursive splitting stops; num_cuts controls candidate cut attempts.
RAG threshold or hierarchical merge RAG built from labels, with color or boundary weights You want to combine neighboring regions after an initial segmentation. Threshold meaning depends on how the edge weights were constructed. Hierarchical merging allows custom merge and weight functions.
Random walker Marker-labeled graph over grayscale or multichannel data You have meaningful seed labels to guide the segmentation. Requires useful markers. Controls include beta, solver mode, and spacing. The API describes it as generally slower than watershed, with good results on noisy data and boundaries with holes.
Watershed Marker basins flooded over an image or elevation surface You need to separate objects or basins and can generate markers. Explicit markers are encouraged. connectivity, mask, and compactness shape the output. An optional watershed line may fail to mark the boundary when marker regions touch.

For automatic initial labels, choose Felzenszwalb or another superpixel method such as SLIC. For grouping existing labels, use a RAG. For segmentation guided by seeds, compare random walker and watershed. The official segmentation examples show these methods and related workflows: scikit-image segmentation examples.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create initial regions with Felzenszwalb

skimage.segmentation.felzenszwalb performs graph-based oversegmentation on an image grid using minimum-spanning-tree-based clustering. Its controls influence the scale and cleanup of the regions rather than specifying a desired semantic class for each one.

  • Increase scale to encourage fewer, larger regions; this is a general tendency, not a fixed region-count guarantee.
  • Use sigma to smooth before segmentation when small image variations are producing distracting regions.
  • Use min_size to affect small components.

Because segment sizes may vary with local contrast, inspect the labels on representative images rather than assuming a single scale produces uniform regions. Exact function signatures can vary by installed scikit-image version; consult that version’s API reference before running code.

Build a region adjacency graph

A RAG represents each labeled region as a node. Edges connect adjacent regions and carry weights that describe a chosen relationship. With mean-color similarity, the weights express color-based similarity; with a boundary map, they can express evidence at the boundary between regions. That edge meaning determines how a later cut or merge should be interpreted.

Use mean-color similarity

skimage.graph.rag_mean_color(image, labels, mode='similarity') constructs a graph using region mean colors and similarity-mode weights. This is a natural starting point when color similarity should help determine which neighboring regions belong together.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use boundary evidence

skimage.graph.rag_boundary(labels, edge_map) builds a RAG using an edge or boundary map. Choose this path when the boundary or elevation signal, rather than average region color, should inform the graph operation.

Before choosing a cut threshold or interpreting results, confirm the installed API’s mode, sigma, and edge-weight direction. A threshold has no useful universal meaning independent of how its weights were constructed.

Partition or merge the graph

Split groups with normalized cut

skimage.graph.cut_normalized(labels, rag) applies normalized cut to a similarity RAG. The typical workflow starts with labels, builds the RAG, and then partitions the labeled regions. The thresh parameter controls when recursive splitting stops, while num_cuts controls candidate cut attempts. The outcome depends on the initial segmentation and on what the graph’s edge weights represent.

from skimage import graph, segmentation

# image is a NumPy array with channels interpreted as expected by scikit-image.
labels = segmentation.slic(
    image, n_segments=250, compactness=10, start_label=1
)
rag = graph.rag_mean_color(image, labels, mode="similarity")
regions = graph.cut_normalized(labels, rag)

This illustrates the documented SLIC → mean-color similarity RAG → normalized-cut API shape; the parameter values are examples, not tested recommendations. See the official graph API example for the documented workflow: skimage.graph API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Merge by a threshold

skimage.graph.cut_threshold(labels, rag, thresh) merges adjacent regions according to the edge-weight threshold. Select thresh only after understanding the scale and direction of the weights produced by the RAG construction. A numeric threshold that makes sense for one edge definition may not make sense for another.

Customize hierarchical merging

skimage.graph.merge_hierarchical supports a customizable hierarchical RAG merge workflow, including merge and weight functions. Use it when a simple threshold rule is insufficient and you need to define how regions combine. Check the installed version’s API for its exact arguments and defaults.

Some graph calls may mutate a RAG in place depending on arguments or defaults. If you need to reuse the original graph for another operation, preserve a copy or verify the behavior in the installed version’s documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use markers when seeds are available

Random walker

Random walker uses marker labels to guide segmentation over grayscale or multichannel image data. It is useful when seeds are meaningful and the image is noisy or boundaries contain holes. Its documented controls include beta, solver mode, and spacing; the scikit-image API describes it as generally slower than watershed.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Watershed

Watershed floods basins over an image or elevation surface from markers. It is often a practical choice for separating objects when markers can be generated or placed. The connectivity, mask, and compactness settings shape the result. If requesting a separating watershed line, be aware that it may fail to mark the boundary when marker regions touch.

Both methods depend on marker quality: a marker layout that does not reflect the intended regions can guide the result in the wrong direction. Compare them on representative images with the markers, connectivity, noise, and expected boundaries in mind. The current controls and cautions are described in the scikit-image segmentation API.

Practical workflow and checks

  1. Load and interpret the image. Work with a NumPy array and establish its channel layout and color interpretation before choosing a method. The scikit-image project paper describes its basic image representation as a standard NumPy array: scikit-image: Image processing in Python.
  2. Choose the graph level. Use Felzenszwalb for direct automatic labels, or use SLIC when you want superpixels as the starting labels for a later RAG operation.
  3. Build the graph for the signal you care about. Choose mean-color similarity for color relationships or a boundary map when boundaries should guide edge weights.
  4. Pick a graph operation. Use normalized cut to recursively partition a similarity RAG, threshold cut to merge by edge weight, or hierarchical merging when you need custom merge logic.
  5. Inspect the labels. Overlay labels on the image and check region counts and boundaries on representative examples. Tune parameters empirically; the API documentation does not establish a universally optimal setting or benchmark for a particular dataset.
  6. Try marker-driven alternatives when appropriate. If seed labels are available, compare random walker and watershed, paying attention to marker placement, connectivity, and noise.

How to evaluate whether the result is useful

Segmentation is not automatically semantic understanding: a region boundary does not by itself say what object or class the region represents. Judge the output against the task’s intended regions and downstream use. Inspect overlays for under- or over-segmentation, check whether graph merges cross meaningful boundaries, and repeat the check across images with different contrast and noise. No single parameter recipe or performance figure is established for an unspecified dataset, so task-specific validation is necessary.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.