Skip to content

outlier_rejection_mad_adaptive

Replace pixels whose deviation from a local median exceeds threshold·MAD.

Category Preprocessing (2-D image)
Backend numpy - implemented here on top of numpy primitives
Version 1.0.1
Reads ctx.image (an ImageFrame)
Writes image, metrics.n_replaced

Vectorised with numpy.lib.stride_tricks.sliding_window_view, so the cost is one O(kernel · pixels) sort. Pixels within the band are replaced by the local median if their deviation exceeds threshold × MAD. The half-pixel border on each side is left untouched (window does not fit there). v1.0.1: rows are processed in chunks so the transient window copies stay around 64 MB regardless of frame size (a 4k² frame with k=5 needed ~6 GB before) — identical output.

Parameters

Parameter Default Required Description
kernel_size 3 - Square neighbourhood size, odd integer ≥ 3.
threshold 3.0 - Multiplier on the local MAD above which a pixel is replaced.
row_lo 0 - First row (inclusive) where the filter applies; 0 = top.
row_hi 0 - Last row (exclusive); 0 ⇒ bottom of the image.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("outlier_rejection_mad_adaptive", ctx, {
    "kernel_size": 3,
    "threshold": 3.0,
    "row_lo": 0,
    "row_hi": 0
})

The CLI loads a single 1-D spectrum with --input; this algorithm needs ctx.image (an ImageFrame). Run it from Python or as a step of a pipeline preset.

{
  "tool": "outlier_rejection_mad_adaptive",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "kernel_size": 3,
      "threshold": 3.0,
      "row_lo": 0,
      "row_hi": 0
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

References

  • Hwang & Haddad 1995, IEEE Trans. Image Processing 4(4):499 — adaptive median filter for impulsive noise.
  • Hoaglin, Mosteller & Tukey 1983, Understanding Robust and Exploratory Data Analysis — Median Absolute Deviation properties.