CommonestFilter[data,r]
filters data by replacing every value with the most common value in its range-r neighborhood.
CommonestFilter[data,{r1,r2,…}]
uses ri for filtering the ![]()
dimension in data.
CommonestFilter
CommonestFilter[data,r]
filters data by replacing every value with the most common value in its range-r neighborhood.
CommonestFilter[data,{r1,r2,…}]
uses ri for filtering the ![]()
dimension in data.
Details
- CommonestFilter, also known as majority filter, is used to filter data by returning the commonest local value, where the extent of the effect is dependent on the value of r.
- The function applied to each range-r neighborhood is Commonest.
- If more than one commonest pixel exists and the center pixel is one of them, the center pixel is used. Otherwise, the pixel is replaced with a random commonest.
- 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 video a Video object - For multichannel images, CommonestFilter replaces each pixel by the commonest pixel vector in the neighborhood.
- CommonestFilter[data,{r1,r2,…}] computes the commonest value in
blocks centered on each sample. - CommonestFilter assumes the index coordinate system for lists and images.
- At the data boundaries, CommonestFilter uses smaller neighborhoods.
Examples
open all close allBasic Examples (3)
Apply a majority filter to a vector of numbers:
CommonestFilter[{0, 1, -1, 1, 2, 1, 3, 3, 3, 1}, 1]Filter a TimeSeries:
ts = TemporalData[TimeSeries, {{{-1, -2, -4, -4, -6, -7, -8, -11, -13, -11, -12, -11, -11, -12, -13,
-13, -12, -11, -9, -8, -8, -7, -6, -7, -10, -11, -10, -9, -10, -9, -7, -7, -7, -8, -7, -7, -7,
-8, -7, -8, -8, -7, -7, -7, -6, -6, -6, -7, -7, ... 2, -73, -73, -73, -74,
-73, -73, -74, -75, -76, -75, -75, -74, -73, -72, -73, -75, -74, -74, -74}}, {{0, 782, 1}}, 1,
{"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 11.1];filtered = CommonestFilter[ts, 50]ListLinePlot[{ts, filtered}, PlotLegends -> {"original data", "filtered"}]Commonest filtering of a color image:
CommonestFilter[[image], 3]Scope (12)
Data (8)
Commonest filtering applied to arbitrary expressions:
CommonestFilter[ {a, b, b, c, c, c, d, d, e}, 2]Majority filtering of a 2D array:
CommonestFilter[(| | | | |
| - | - | - | - |
| 1 | 1 | 2 | 0 |
| 2 | 3 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 0 | 1 | 2 | 3 |), 1]//MatrixFormdata = {Quantity[2, "Meters"], Quantity[0, "Meters"], Quantity[0, "Meters"], Quantity[3, "Meters"], Quantity[0, "Meters"], Quantity[1, "Meters"], Quantity[3, "Meters"], Quantity[1, "Meters"], Quantity[1, "Meters"], Quantity[3, "Meters"], Quantity[3, "Meters"], Quantity[1, "Meters"]};filtered = CommonestFilter[data, 1]Filter an EventSeries:
es = TemporalData[EventSeries, {{{8, 3, 1, 4, 10, 9, 4, 8, 5, 3, 5, 6, 1, 8, 3, 3, 2, 5, 0, 6, 4, 4, 3,
10, 0, 1, 1, 10, 3, 5, 2, 1, 8, 8, 2, 10, 9, 5, 4, 9, 8, 5, 1, 2, 8, 10, 0, 5, 8, 10, 0, 4, 4,
5, 8, 0, 8, 2, 3, 5, 9, 6, 5, 6, 10, 1, 8, 4 ... , 4, 0, 0, 7, 4, 6, 6, 6, 7,
7, 1, 9, 2, 3, 9, 10, 6, 2, 9, 7, 10, 5, 9, 7, 7, 9, 6, 7, 8, 6, 7, 8, 0, 2, 5, 5, 8, 7, 0, 9,
2, 2, 4, 5}}, {{0, 149, 1}}, 1, {"Discrete", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> None}}, False, 10.1];filtered = CommonestFilter[es, 10]ListPlot[{es, filtered}, PlotLegends -> {"original data", "filtered"}, Filling -> Axis]Filter an Audio signal:
a = Import["ExampleData/rule30.wav"];b = CommonestFilter[a, 35]AudioPlot[{a, b}]Filtering a 2D grayscale image:
CommonestFilter[[image], 5]CommonestFilter[Video["ExampleData/fish.mp4"], 3]Apply commonest filtering to a 3D volume:
CommonestFilter[ExampleData[{"TestImage3D", "CTengine"}], 2]Parameters (4)
Specify one radius to be used in all directions:
CommonestFilter[[image], 3]Increasing the radius will increase the regions of uniform value in images:
Table[Labeled[CommonestFilter[[image], r], Text["*r* = " <> ToString@r]], {r, {1, 3, 6}}]Majority filtering just in the first direction:
CommonestFilter[[image], {10, 0}]CommonestFilter[[image], {0, 10}]Commonest filtering of a 3D image in the vertical direction only:
CommonestFilter[[image], {15, 0, 0}]Filtering of the horizontal planes only:
CommonestFilter[[image], {0, 5, 5}]Applications (2)
Properties & Relations (1)
Commonest filter gives the same result as MedianFilter on binary images:
i = [image];
CommonestFilter[i, 3] === MedianFilter[i, 3]Possible Issues (1)
Majority filtering may not have the desired effect when applied to real-valued data, since all sample values may be unique:
x = RandomReal[{0, 3}, 8]CommonestFilter[x, 1]Quantize the sample values to overcome this problem:
CommonestFilter[Floor[x], 1]//NTech Notes
Related Guides
History
Introduced in 2008 (7.0) | Updated in 2012 (9.0) ▪ 2015 (10.2) ▪ 2016 (11.0) ▪ 2025 (14.3)
Text
Wolfram Research (2008), CommonestFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/CommonestFilter.html (updated 2025).
CMS
Wolfram Language. 2008. "CommonestFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/CommonestFilter.html.
APA
Wolfram Language. (2008). CommonestFilter. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CommonestFilter.html
BibTeX
@misc{reference.wolfram_2026_commonestfilter, author="Wolfram Research", title="{CommonestFilter}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/CommonestFilter.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_commonestfilter, organization={Wolfram Research}, title={CommonestFilter}, year={2025}, url={https://reference.wolfram.com/language/ref/CommonestFilter.html}, note=[Accessed: 13-June-2026]}