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.
How it works¶
- Take the square window around the pixel.
- Find its smallest value.
- Write that value as the new pixel.
Mathematical foundation¶
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¶
- Pad the image with the border mode.
- For each row, find the smallest value in each run of size pixels.
- For each column of that result, find the smallest value in each run of size pixels.
- 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¶
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.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/nonlinear/nonlinear5b.test.ts
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Section 5.3, order-statistic filters.
- SciPy documentation, scipy.ndimage.minimum_filter. https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.minimum_filter.html