WOLFRAM

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 ^(th)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:
  • listarbitrary-rank numerical array
    tseriestemporal data such as TimeSeries, TemporalData,
    imagearbitrary Image or Image3D object
    audioan Audio 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 allclose all

Basic Examples  (3)Summary of the most common use cases

Apply a majority filter to a vector of numbers:

Out[45]=45

Filter a TimeSeries:

Out[2]=2
Out[3]=3

Commonest filtering of a color image:

Out[1]=1

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

Data  (7)

Commonest filtering applied to arbitrary expressions:

Out[1]=1

Majority filtering of a 2D array:

Filter a quantity array:

Out[2]=2

Filter an EventSeries:

Out[2]=2
Out[3]=3

Filter an Audio signal:

Out[2]=2
Out[3]=3

Filtering a 2D grayscale image:

Out[1]=1

Apply commonest filtering to a 3D volume:

Out[1]=1

Parameters  (4)

Specify one radius to be used in all directions:

Out[101]=101

Increasing the radius will increase the regions of uniform value in images:

Out[1]=1

Majority filtering just in the first direction:

Out[1]=1

Second direction:

Out[2]=2

Commonest filtering of a 3D image in the vertical direction only:

Out[1]=1

Filtering of the horizontal planes only:

Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Replacing each pixel with the most common color in its neighborhood creates a posterization effect:

Out[20]=20

Majority filtering removes noise from a binary image:

Out[1]=1

Properties & Relations  (1)Properties of the function, and connections to other functions

Commonest filter gives the same result as MedianFilter on binary images:

Out[12]=12

Possible Issues  (1)Common pitfalls and unexpected behavior

Majority filtering may not have the desired effect when applied to real-valued data, since all sample values may be unique:

Out[86]=86
Out[87]=87

Quantize the sample values to overcome this problem:

Out[93]=93

Neat Examples  (1)Surprising or curious use cases

Commonest filtering applied to random noise:

Out[1]=1
Wolfram Research (2008), CommonestFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/CommonestFilter.html (updated 2016).
Wolfram Research (2008), CommonestFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/CommonestFilter.html (updated 2016).

Text

Wolfram Research (2008), CommonestFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/CommonestFilter.html (updated 2016).

Wolfram Research (2008), CommonestFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/CommonestFilter.html (updated 2016).

CMS

Wolfram Language. 2008. "CommonestFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/CommonestFilter.html.

Wolfram Language. 2008. "CommonestFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. 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

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

BibTeX

@misc{reference.wolfram_2025_commonestfilter, author="Wolfram Research", title="{CommonestFilter}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/CommonestFilter.html}", note=[Accessed: 19-June-2025 ]}

@misc{reference.wolfram_2025_commonestfilter, author="Wolfram Research", title="{CommonestFilter}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/CommonestFilter.html}", note=[Accessed: 19-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_commonestfilter, organization={Wolfram Research}, title={CommonestFilter}, year={2016}, url={https://reference.wolfram.com/language/ref/CommonestFilter.html}, note=[Accessed: 19-June-2025 ]}

@online{reference.wolfram_2025_commonestfilter, organization={Wolfram Research}, title={CommonestFilter}, year={2016}, url={https://reference.wolfram.com/language/ref/CommonestFilter.html}, note=[Accessed: 19-June-2025 ]}