MeanShift

MeanShift[list,d]

replaces each element in list by the mean of the values of all elements that differ by less than d.

MeanShift[list,d,{p1,p2,}]

returns the list where only the specified parts pi are replaced with mean-shifted values.

MeanShift[image,]

mean shift of the pixel values in image.

Details and Options

  • MeanShift is also known as mode seeking and is typically used to smooth data arrays and images.
  • MeanShift preserves the ordering of the input elements.
  • In MeanShift[image,d,parts], parts can be a marker image or a list of {row,column} positions.
  • The following options can be given:
  • DistanceFunction EuclideanDistancedistance metric function
    MaxIterations 1maximum number of iterations to perform
    Tolerance 0allowed tolerance to assume convergence
    Weights Automaticweights to use for computing the mean
  • With Tolerance->t, mean-shift iterations stop if no point changes by more than t.
  • By default, unit weights are used. Using Weights->f, function f applied to rescaled distances between elements is used to compute and return a weighted mean of the values. Distances between 0 and d are rescaled to be in the range from 0 and 1.
  • Typical settings for Weights include:
  • UnitStepunit weights (default)
    UnitTrianglelinearly decreasing weight
    "Gaussian"weights based on a Gaussian window with sigma
    {"Gaussian",σ}Gaussian window with sigma σ
  • Common settings for the DistanceFunction option are:
  • ManhattanDistanceManhattan or "city block" distance
    EuclideanDistanceEuclidean distance
    SquaredEuclideanDistancesquared Euclidean distance
    NormalizedSquaredEuclideanDistancenormalized squared Euclidean distance
    CosineDistanceangular cosine distance
    CorrelationDistancecorrelation coefficient distance
    fuse an arbitrary function f

Examples

open allclose all

Basic Examples  (3)

Mean shift of a list of integers:

Mean shift of a list of vectors:

Mean shift of an image's pixels after multiple iterations:

Scope  (4)

Remove uniform noise from a dataset:

Mean-shift algorithm applied to symbolic expressions:

Mean-shift algorithm applied to a subset of the points:

Precision of the input is preserved:

Options  (8)

DistanceFunction  (3)

By default, EuclideanDistance is used:

Specify the distance function:

Use a custom distance function:

MaxIterations  (2)

By default, only one iteration of mean shift is applied to input:

Use MaxIterations to specify the number of iterations:

Use MaxIterations->Infinity to run until convergence:

Use MaxIterations to iteratively smooth data:

Tolerance  (1)

By default, zero tolerance is used:

Specify the accepted tolerance:

Weights  (2)

By default, uniform weights are used:

Weigh neighbors linearly, based on their distance from each sample:

Weigh neighbors exponentially, based on their squared distance from each sample:

By "Gaussian" weights for color segmentation:

With default uniform weights:

Applications  (9)

Smoothing  (2)

Find large-scale features in a noisy dataset:

Image smoothing using mean shift of 5D features in the joint spatial-range domain:

Use LABColor values, suitable for computing color distances:

Compute spatial location features normalized to the range 0 to 1:

Construct 5D features from color and location of pixels:

Perform one iteration of mean-shift filtering using "Gaussian" weights and EuclideanDistance, which is equivalent to multiplying Gaussian-weighted spatial and range features:

Create the output image using the filtered color values:

Perform 10 iterations:

Mean-Shift Displacement  (2)

Compute a 1D mean-shift vector:

Generate unimodal 2D data:

Compute the trajectory of a point as it iteratively ascends toward the mode:

Visualize the norm and direction of the successive mean-shift vectors:

Visualize the ascent:

Find Modes of Estimated Distribution  (1)

Get sample data from some distribution with three modes: 0, 2, and 4:

Apply mean shift until convergence for samples that tessellates the data:

Prune points that are not local maxima of the underlying PDF by restarting mean shift from a perturbed position:

Find modes by gathering the nearby peaks:

Clustering  (2)

Generate data from some distribution:

Apply mean shift until all data points have converged:

Gather the result into clusters:

Visualize the clustering:

Generate a large amount of data from some distribution:

Compute trajectories for a fraction of the data samples:

Merge paths that end within radius of each other:

Label each trajectory and compute the corresponding nearest function:

Each unlabeled sample is assigned the label of the closest trajectory:

Visualize the clustering:

Computing the mean shift until convergence for the entire dataset would take much longer:

Image Segmentation  (2)

Iterate mean-shift filtering in the 3D feature space of the "LAB" color components:

Perform mean-shift filtering in the 5D spatial-range feature domain:

Merge components whose feature values are apart by less than the radius:

Compute the final segments and quantized image:

Properties & Relations  (3)

Perform mean shift on some parts of a list:

Extract the mean-shifted elements:

Perform mean shift on some parts of an image:

Extract the mean-shifted pixel values:

The mean-shift vector is proportional to the gradient density estimate normalized by the density estimate:

Neat Examples  (1)

Show multiple iterations of mean shift:

Wolfram Research (2010), MeanShift, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanShift.html (updated 2014).

Text

Wolfram Research (2010), MeanShift, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanShift.html (updated 2014).

CMS

Wolfram Language. 2010. "MeanShift." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MeanShift.html.

APA

Wolfram Language. (2010). MeanShift. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MeanShift.html

BibTeX

@misc{reference.wolfram_2023_meanshift, author="Wolfram Research", title="{MeanShift}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MeanShift.html}", note=[Accessed: 18-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_meanshift, organization={Wolfram Research}, title={MeanShift}, year={2014}, url={https://reference.wolfram.com/language/ref/MeanShift.html}, note=[Accessed: 18-April-2024 ]}