Skip to content

Min filter

Fact Value
Also called Minimum filter, Local minimum
Status Implemented and tested
Family Nonlinear spatial filters
Engine Browser
Type Nonlinear, spatial, order statistic
Output Image
Operator shown as rank (exact)
Support radius floor(size / 2)
Code web/src/core/filters/nonlinear/min-max.ts, minFilter
Operator code web/src/core/filters/nonlinear/min-max.ts, extremeRank
Channels RGB, Brightness only

Overview

The min filter replaces each pixel with the smallest value of its window. White specks disappear, because a window almost always holds a darker value. Dark areas grow by the window radius, and bright areas shrink by the same amount.

Three panels: disks on a dark background with white specks, the result of a 3x3 min filter with no specks and slightly smaller disks, and a 3x3 median with no specks. Three panels: disks on a dark background with white specks, the result of a 3x3 min filter with no specks and slightly smaller disks, and a 3x3 median with no specks.
The min filter removes white specks. The median also removes them but keeps small bright dots.

How it works

  1. Take the square window around the pixel.
  2. Find its smallest value.
  3. Write that value as the new pixel.

Mathematical foundation

\[ I_{\text{out}}(x,y) = \min\,\{\, I(x+i,\, y+j) \;:\; -r \le i \le r,\; -r \le j \le r \,\}, \qquad r = (3 - 1) / 2 \]

The formula shows the default parameter values.

where

  • \(I\): Input channel value
  • \(I_{\text{out}}\): Output channel value
  • \((x, y)\): Pixel position
  • \(r\): Window radius in pixels

The output is the smallest value in the window. It is the first value of the sorted window, so it is the rank-order filter with rank 1. It is also gray erosion with a flat square structuring element.

The minimum is the first order statistic. It is also gray erosion with a flat square structuring element. The min over a square equals the min over the columns of the min over the rows, so the filter runs as two passes of k values each. The min filter never makes a new value. It only copies values that are in the window.

Kernel or operator

The Inspector shows the window, the number of values and the rank that is used. The Rank stepper in the Learn panel shows the sorted window at any pixel and the value the filter gives there. For the min filter the rank is 1.

Algorithm

  1. Pad the image with the border mode.
  2. For each row, find the smallest value in each run of size pixels.
  3. For each column of that result, find the smallest value in each run of size pixels.
  4. Write it to the output pixel.

Parameters

Parameter Default Values Meaning
Window size size 3 3 to 25, odd px Width and height of the square window.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

extremePlane in web/src/core/filters/nonlinear/window.ts runs a row pass and a column pass. The morphology filters of Phase 5d share this code for flat rectangles. Values keep their fractions, so a brightness plane is not rounded. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts. It handles the border mode, the channel scope, alpha and the rounding to 8 bits. Each strip of the image gets a halo as wide as the support radius, so strips give exactly the pixels of a whole-image run.

Worked example

\[ W = \begin{bmatrix} 52 & 61 & 58 \\ 49 & 255 & 63 \\ 55 & 0 & 60 \end{bmatrix} \]

Sorted: 0, 49, 52, 55, 58, 60, 61, 63, 255. The min filter takes the first value, 0. The pepper pixel 0 wins, so this window turns black. The salt pixel 255 has no effect.

Complexity

  • Time: \(O(N\,k)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel and k is the window width. A square window is a row times a column, so a row pass and a column pass of k values each give the minimum of all k^2 values.

Artifacts and limitations

Limitations

  • Makes pepper noise worse. Dark specks grow into squares.
  • Shrinks bright objects and thin bright lines.

Artifacts

  • Square dark blocks around dark pixels with large windows.

Tests

The filter is compared with scipy.ndimage.minimum_filter for window sizes 3 and 5 and all five border modes. A unit test checks that the sliding-histogram rank code gives the same result with rank 1.

References