MeanShiftFilter
✖
MeanShiftFilter
filters data by replacing every value by the mean of the pixels in a range-r neighborhood and whose value is within a distance d.
Details and Options


- MeanShiftFilter is used to locally smooth data and diminish noise while preserving significant jumps such as edges in images, where the amount of smoothing is dependent on the values of r and d.
- The function applied to each range-r neighborhood is MeanShift.
- The data can be any of the following:
-
list arbitrary-rank numerical array tseries temporal data such as TimeSeries, TemporalData, … image arbitrary Image or Image3D object audio an Audio object - For multichannel images and audio signals, the distance is computed between channel vectors.
- MeanShiftFilter[data,{r1,r2,…},d] computes the mean shift value in
blocks centered on each sample.
- MeanShiftFilter assumes the index coordinate system for lists and images.
- At the data boundaries, MeanShiftFilter uses smaller neighborhoods.
- The following options can be given:
-
DistanceFunction EuclideanDistance how to compute the distance between values MaxIterations 1 maximum number of iterations to be performed - For a complete list of possible settings for DistanceFunction, see the reference page for MeanShift.
- The possible range for the distance parameter d depends on the distance function as well as the dimension of the color space.


Background & Context
- MeanShiftFilter is a filter for smoothing images to remove local variations typically caused by noise, rough textures, etc. MeanShiftFilter is often used as a preprocessing step before doing other image analysis operations such as segmentation.
- Unlike most other noise-removing filters (e.g. MeanFilter), MeanShiftFilter preserves edges in the image. Other similar functions include PeronaMalikFilter, BilateralFilter, and NonlocalMeansFilter.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Mean-shift filtering of a vector:

https://wolfram.com/xid/0fq3vtnyg10bu-s47pnq

Filter a TimeSeries:

https://wolfram.com/xid/0fq3vtnyg10bu-wxgjw

https://wolfram.com/xid/0fq3vtnyg10bu-g9fo2


https://wolfram.com/xid/0fq3vtnyg10bu-dulvtd

Mean-shift filtering of a color image:

https://wolfram.com/xid/0fq3vtnyg10bu-oefipw

Scope (11)Survey of the scope of standard use cases
Data (6)

https://wolfram.com/xid/0fq3vtnyg10bu-39jnjr

Mean-shift filtering of a 2D array:

https://wolfram.com/xid/0fq3vtnyg10bu-cxywqj

Filter a TimeSeries:

https://wolfram.com/xid/0fq3vtnyg10bu-62t833

https://wolfram.com/xid/0fq3vtnyg10bu-77v7p5


https://wolfram.com/xid/0fq3vtnyg10bu-18tdm0

Filter an Audio signal:

https://wolfram.com/xid/0fq3vtnyg10bu-p90slf

https://wolfram.com/xid/0fq3vtnyg10bu-o6g2aw


https://wolfram.com/xid/0fq3vtnyg10bu-j5yrn4

Mean-shift filtering of a grayscale image:

https://wolfram.com/xid/0fq3vtnyg10bu-nddd2h

Mean-shift filtering of a 3D image:

https://wolfram.com/xid/0fq3vtnyg10bu-bjekx4

Parameters (5)
Specify one radius to be used in all directions:

https://wolfram.com/xid/0fq3vtnyg10bu-tlzgi7

Mean-shift filtering in just the first direction:

https://wolfram.com/xid/0fq3vtnyg10bu-gdx3zh

Filtering in just the second direction:

https://wolfram.com/xid/0fq3vtnyg10bu-79md3z

Mean-shift filtering of a 3D image in the vertical direction only:

https://wolfram.com/xid/0fq3vtnyg10bu-camcbp

Mean-shift filtering of a 3D image in the horizontal planes only:

https://wolfram.com/xid/0fq3vtnyg10bu-5u7xo

Mean-shift filter averages only over pixels that differ in value by less than d:

https://wolfram.com/xid/0fq3vtnyg10bu-e9uvy3

Options (3)Common values & functionality for each option
DistanceFunction (2)
By default, EuclideanDistance is used:

https://wolfram.com/xid/0fq3vtnyg10bu-vy4lw

Specify the distance function:

https://wolfram.com/xid/0fq3vtnyg10bu-4g3vi2

MaxIterations (1)
By default, only one iteration of mean shift is applied to input:

https://wolfram.com/xid/0fq3vtnyg10bu-fnsh5o

Use MaxIterations to specify the number of iterations:

https://wolfram.com/xid/0fq3vtnyg10bu-zzjjv

Applications (2)Sample problems that can be solved with this function
Properties & Relations (1)Properties of the function, and connections to other functions
MeanShiftFilter is equivalent to MeanFilter for distance d greater than the data dynamic range:

https://wolfram.com/xid/0fq3vtnyg10bu-eoy13k

https://wolfram.com/xid/0fq3vtnyg10bu-1qqmmg

Neat Examples (1)Surprising or curious use cases
Show how MeanShiftFilter iteratively shifts values until they converge:

https://wolfram.com/xid/0fq3vtnyg10bu-2q9fdn

https://wolfram.com/xid/0fq3vtnyg10bu-2g9n2v


https://wolfram.com/xid/0fq3vtnyg10bu-v27t6q

https://wolfram.com/xid/0fq3vtnyg10bu-w91jgl

Wolfram Research (2010), MeanShiftFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanShiftFilter.html (updated 2016).
Text
Wolfram Research (2010), MeanShiftFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanShiftFilter.html (updated 2016).
Wolfram Research (2010), MeanShiftFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanShiftFilter.html (updated 2016).
CMS
Wolfram Language. 2010. "MeanShiftFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/MeanShiftFilter.html.
Wolfram Language. 2010. "MeanShiftFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/MeanShiftFilter.html.
APA
Wolfram Language. (2010). MeanShiftFilter. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MeanShiftFilter.html
Wolfram Language. (2010). MeanShiftFilter. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MeanShiftFilter.html
BibTeX
@misc{reference.wolfram_2025_meanshiftfilter, author="Wolfram Research", title="{MeanShiftFilter}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/MeanShiftFilter.html}", note=[Accessed: 29-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_meanshiftfilter, organization={Wolfram Research}, title={MeanShiftFilter}, year={2016}, url={https://reference.wolfram.com/language/ref/MeanShiftFilter.html}, note=[Accessed: 29-March-2025
]}