Skip to content

Quickshift

Fact Value
Also called Quick shift, Quickshift superpixels
Status Implemented and tested
Family Segmentation and regions
Engine Science engine
Type Nonlinear, spatial, mode seeking
Output Labels
Operator shown as algorithm (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/segmentation.py, quickshift_filter
Operator code engine/src/pixelnexus_engine/filters/segmentation.py, quickshift_representation
Packages scikit-image

Overview

Quickshift groups pixels around the peaks of their density in color and position, after Vedaldi and Soatto. Each pixel links to its nearest neighbor that is more typical, with a higher density. The links climb toward the peaks, and long links are cut. Each tree of links that remains is a region, so the number of regions follows the image. The regions go to the Features panel with their area, centroid and mean brightness, and are drawn over the image in their label colors. Click a row number in the panel to make that region the selection, or select all regions at once. The selection can then be saved or exported as a mask, as any selection. The filter runs in the PixelNexus engine, with scikit-image.

The input has colored squares of 20 pixels and red disks, with grainy noise. The regions of Quickshift with the defaults follow the squares and the disks closely, with a few tiny specks. The boundaries panel draws yellow lines along the squares and around the disks. The mean colors panel looks like a clean copy of the input. The input has colored squares of 20 pixels and red disks, with grainy noise. The regions of Quickshift with the defaults follow the squares and the disks closely, with a few tiny specks. The boundaries panel draws yellow lines along the squares and around the disks. The mean colors panel looks like a clean copy of the input.
A test image with colored squares and red disks, with noise of sigma 6. Then the regions of Quickshift with the defaults in their label colors, the boundaries in yellow over the image, and each region filled with its mean color.

How it works

  1. Turn the image into CIELAB and join color and position.
  2. Estimate the density at each pixel with a Gaussian kernel.
  3. Link each pixel to its nearest neighbor of higher density.
  4. Cut links longer than the longest link, and label the trees.

Mathematical foundation

\[ P(x) = \sum_{y} e^{-\lVert f(x) - f(y) \rVert^2 / (2 \sigma_k^2)}, \qquad x \to \arg\min_{y : P(y) > P(x)} \lVert f(x) - f(y) \rVert \]

The formula shows the default parameter values.

where

  • \(f(x)\): The weighted color and the position of pixel x
  • \(P(x)\): The density at pixel x
  • \(\sigma_k\): The kernel size

f(x) holds the CIELAB color of pixel x, weighted by the color weight, and its position. The density P sums a Gaussian of the kernel size over the nearby pixels. Each pixel links to the nearest pixel with a higher density, so the links climb toward the peaks of the density. Links longer than the longest link are cut. The links that remain form trees, one per peak, and each tree is a region. Unlike mean shift, each pixel moves once, which makes it quick.

Quickshift is a mode-seeking method, like mean shift. Mean shift moves every point step by step uphill on the density until it stops at a peak. Quickshift instead moves each point once, straight to its nearest neighbor of higher density. That builds a tree whose roots are the peaks, without iterating.

The density joins color and position. The color weight sets how much color counts against position. With 1, colors that differ split regions even when they touch. With small values, regions become compact blobs whatever their color.

Cutting links longer than the longest link separates the trees. Without the cut, every pixel would link up to the single highest peak of the image.

Kernel or operator

There is no kernel. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Output output Regions Regions, Boundaries over the image, Mean color of each region The regions as a label map, drawn over the image and listed in the Features panel. Or the boundaries in yellow over the image, or each region filled with its mean color.
Color weight ratio 1 0 to 1 How much color counts against position, from 0 to 1. scikit-image uses 1.
Kernel size kernelSize 5 1 to 20 The width of the Gaussian that estimates the density. scikit-image uses 5.
Longest link maxDist 10 1 to 100 Links longer than this, in color and position, are cut. scikit-image uses 10.
Smoothing sigma 0 0 to 5 px The sigma of a Gaussian blur first. scikit-image uses 0, no blur.

Implementation

quickshift_filter in engine/src/pixelnexus_engine/filters/segmentation.py calls skimage.segmentation.quickshift on the RGB image from 0 to 1, which scikit-image turns into CIELAB. It uses scikit-image's fixed seed 42, which breaks ties between equal densities, so a run always gives the same regions. Here scikit-image searches a window that reaches 3 times the kernel size, rounded up, on each side. Its labels start at 0, so the filter adds 1. The boundaries output draws skimage.segmentation.mark_boundaries in yellow, and the mean colors output fills each region with its rounded mean.

The regions output is a label map. The engine sends it with a table of the regions, and the studio draws it over the image. See the science engine for how label maps travel.

Worked example

Kernel size Longest link Regions Mean area (px)
3 5 517 50
3 10 77 332
3 20 74 346
5 5 472 54
5 10 72 356
5 20 71 361
8 5 480 53
8 10 72 356
8 20 70 366

The test image of the figure, 160 x 160 pixels, with the other settings at their defaults. The colored squares alone would give 64 regions, and the disks cut some of them.

A longest link of 5 is shorter than the noise, so the image falls into about 500 tiny regions. A longest link of 10, the default, gives 72 regions, close to the 64 squares, and 20 gives about the same. The kernel size changes little on this image, since its regions are large and flat.

Complexity

  • Time: \(O(N K^2)\)
  • Memory: \(O(N)\)

N is the number of pixels and K the reach of the search window on each side, 3 times the kernel size rounded up.

Artifacts and limitations

Limitations

  • Slower than SLIC and Felzenszwalb for large kernels.
  • Flat areas break into many regions, since their density has no clear peaks.

Artifacts

  • Speckled regions in flat areas.

Tests

The labels must equal scikit-image's quickshift with seed 42 plus 1. On four flat colored quarters with a little noise, a kernel size of 3 and a longest link of 30, it must find exactly the four quarters. The boundaries and mean colors outputs must match mark_boundaries and the rounded means. The representation must have its three stages.

References

  • Vedaldi, A., and Soatto, S. Quick shift and kernel methods for mode seeking. European Conference on Computer Vision (ECCV), Lecture Notes in Computer Science 5305, 705 to 718, 2008. DOI 10.1007/978-3-540-88693-8_52.
  • scikit-image documentation, skimage.segmentation.quickshift.