MaxFilter
Details
- MaxFilter is a nonlinear filter commonly used to locally smooth data and diminish pepper-like noise, where the amount of smoothing is dependent on the value of r.
- The function applied to each range-r neighborhood is Max.
- 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, MaxFilter replaces each pixel by a pixel in its neighborhood that has the maximum total intensity, averaged over all channels.
- MaxFilter[data,{r1,r2,…}] computes the maximum value in
blocks centered on each sample. - MaxFilter assumes the index coordinate system for lists and images.
- At the data boundaries, MaxFilter uses smaller neighborhoods.
Examples
open all close allBasic Examples (3)
MaxFilter[ {1, 2, 3, 2, 1}, 1]Filter a TimeSeries:
ts = TemporalData[TimeSeries, {{{0., -0.27267267057145633, -0.6672983789995302, -0.5338541947930846,
-0.6117404489279314, -0.6755527076595494, -0.02125421294486496, -0.10792797291843935,
-0.6138271235477938, -0.3248568606554575, -0.08843449054 ... 2053424, -0.49980440691873723, -0.5388679788215971,
-0.4101602764645551}}, {{0, 1., 0.01}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1,
{ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False,
10.1];filtered = MaxFilter[ts, .1]ListLinePlot[{ts, filtered}, PlotLegends -> {"original data", "filtered"}]Maximum filtering of a color image:
MaxFilter[[image], 6]Scope (13)
Data (8)
Maximum filtering of a numeric vector:
MinFilter[{0, 3, 8, 2}, 1]MaxFilter[ {a, b, c}, 1]Maximum filtering of a 2D array:
MaxFilter[(| | | | |
| - | - | - | - |
| 0 | 3 | 8 | 2 |
| 7 | 6 | 9 | 6 |
| 5 | 8 | 4 | 0 |
| 3 | 5 | 1 | 6 |), 1]//MatrixFormMaximum filtering of a list of Quantity objects:
data = {Quantity[9, "Feet"], Quantity[86, "Inches"], Quantity[27.1, "Meters"], Quantity[79, "Feet"], Quantity[90, "Feet"], Quantity[41, "Inches"], Quantity[99, "Inches"], Quantity[6, "Feet"], Quantity[38, "Feet"], Quantity[89, "Feet"], Quantity[53, "Feet"], Quantity[85, "Meters"], Quantity[92, "Meters"], Quantity[95, "Meters"], Quantity[49, "Feet"]};ListLinePlot[{data, MaxFilter[data, 2]}, PlotRange -> All]Filter an Audio signal:
a = Import["ExampleData/rule30.wav"];b = MaxFilter[a, 35]AudioPlot[{a, b}]Filtering a 2D grayscale image:
MaxFilter[[image], 3]MaxFilter[Video["ExampleData/fish.mp4"], 3]MaxFilter[[image], 2]Parameters (5)
Specify one radius to be used in all directions:
MaxFilter[[image], 1]Increasing the radius will result in brighter images:
Table[Labeled[MaxFilter[[image], r], Text["*r* = " <> ToString@r]], {r, {1, 2, 4}}]Maximum filtering just in the first direction:
MaxFilter[[image], {5, 0}]Filtering just in the second direction:
MaxFilter[[image], {0, 5}]Maximum filtering of a 3D image in the vertical direction only:
MaxFilter[[image], {5, 0, 0}]Filtering of a 3D image in the horizontal planes only:
MaxFilter[[image], {0, 3, 3}]Applications (4)
Remove pepper noise from an astronomical image:
MaxFilter[[image], 1]Use a maximum filter to dilate the brighter parts of a color image:
MaxFilter[[image], 1]Dilate the brighter parts of an image to remove thin, dark features:
MaxFilter[[image], 1]Use maximum filtering to locate borders in an image:
i = [image];
ImageSubtract[MaxFilter[i, 1], i]Properties & Relations (3)
Maximum filtering is the same as Dilation with a box structuring element:
MaxFilter[[image], 1] == Dilation[[image], 1]Maximum filtering is the same as ImageFilter with function Max:
MaxFilter[[image], 1] == ImageFilter[Max[Flatten[#]]&, [image], 1]Subsequent application of MaxFilter and MinFilter is the same as Closing:
MinFilter[MaxFilter[[image], 6], 6]History
Introduced in 2008 (7.0) | Updated in 2015 (10.2) ▪ 2016 (11.0) ▪ 2025 (14.3)
Text
Wolfram Research (2008), MaxFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/MaxFilter.html (updated 2025).
CMS
Wolfram Language. 2008. "MaxFilter." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/MaxFilter.html.
APA
Wolfram Language. (2008). MaxFilter. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MaxFilter.html
BibTeX
@misc{reference.wolfram_2026_maxfilter, author="Wolfram Research", title="{MaxFilter}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/MaxFilter.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_maxfilter, organization={Wolfram Research}, title={MaxFilter}, year={2025}, url={https://reference.wolfram.com/language/ref/MaxFilter.html}, note=[Accessed: 12-June-2026]}