# ImageFilters

ImageFilters applies an ordered pipeline of post‑processing filters to depth‑like grayscale images (RAW8/RAW16). It is currently
most useful for ToF depth pipelines and for replaying depth on the host. The node provides median, spatial, speckle, and temporal
filtering in a single place. If no filters are configured, it acts as a passthrough.

For standard live StereoDepth pipelines, prefer using the built‑in StereoDepthConfig.PostProcessing instead of this node (see
Notes).

## How to place it

#### Python

```python
with dai.Pipeline() as pipeline:
    imageFilters = pipeline.create(dai.node.ImageFilters)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto imageFilters = pipeline.create<dai::node::ImageFilters>();
```

## Inputs and Outputs

Additional port:

 * inputConfig — accepts ImageFiltersConfig messages for runtime configuration

## Basic usage

Filter a StereoDepth disparity stream with a single filter:

#### Python

```python
with dai.Pipeline() as p:
    left = p.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    right = p.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
    outL = left.requestOutput((640, 400), fps=20)
    outR = right.requestOutput((640, 400), fps=20)

    stereo = p.create(dai.node.StereoDepth)
    outL.link(stereo.left)
    outR.link(stereo.right)

    filters = p.create(dai.node.ImageFilters)
    filters.setRunOnHost(True)  # Required on RVC2
    filters.build(stereo.disparity)  # build without preset

    # Single Spatial filter enabled (all other params default)
    spatial = dai.node.ImageFilters.SpatialFilterParams()
    spatial.enable = True
    filters.initialConfig.filterParams = [spatial]
```

#### C++

```cpp
dai::Pipeline p;
auto left  = p.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
auto right = p.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
left->requestOutput({640,400}, 20);
right->requestOutput({640,400}, 20);

auto stereo = p.create<dai::node::StereoDepth>();

auto filters = p.create<dai::node::ImageFilters>();
filters->setRunOnHost(true); // Required on RVC2
filters->build(stereo->disparity); // build without preset

// Single Spatial filter enabled
std::vector<dai::FilterParams> params;
dai::filters::params::SpatialFilter sp{}; sp.enable = true;
params.push_back(sp);
filters->initialConfig->filterParams = params;
```

## Presets

dai::ImageFiltersPresetMode / dai.ImageFiltersPresetMode (currently ToF‑tuned presets only):

 * TOF_LOW_RANGE — stronger temporal + spatial smoothing for ~0.2–2 m
 * TOF_MID_RANGE — balanced defaults for ~0.2–5 m
 * TOF_HIGH_RANGE — aggressive persistence + median for longer ranges

Notes:

 * These presets are named and tuned for ToF usage and are optional.
 * For general StereoDepth pipelines, prefer defining a custom pipeline (see Basic usage) and adjust parameters to your scene.

## Filter parameters

Available parameter types (same models as StereoDepth post‑processing):

 * MedianFilterParams — MEDIAN_OFF, KERNEL_3x3, KERNEL_5x5
 * SpatialFilterParams — enable, holeFillingRadius, alpha, delta, numIterations
 * SpeckleFilterParams — enable, speckleRange, differenceThreshold
 * TemporalFilterParams — enable, persistencyMode, alpha, delta

## Notes

 * Supported input types: RAW8 and RAW16 only.
 * Median kernel up to 5×5 in this node (7×7 is not accepted).
 * On RVC2, device execution is not supported; call setRunOnHost(True).
 * If no filters are configured, the node acts as a passthrough.

### Recommendation for StereoDepth (non‑ToF)

If you are using live StereoDepth, rely on its built‑in post‑processing and keep temporal filtering conservative or disabled.
Example (Python):

#### Python

```python
stereo = p.create(dai.node.StereoDepth)
# … link left/right …
stereo.initialConfig.postProcessing.temporalFilter.enable = False
stereo.initialConfig.postProcessing.temporalFilter.delta = 100
```

## Examples of functionality

 * [Stereo Depth Filters](https://docs.luxonis.com/software-v3/depthai/examples/stereo_depth/stereo_depth_filters.md) — example of
   using ImageFilters with StereoDepth disparity output

## Reference

### dai::node::ImageFilters

Kind: class

#### std::shared_ptr< ImageFiltersConfig > initialConfig

Kind: variable

Initial config for image filters.

#### Node::Input input

Kind: variable

Input for image frames to be filtered

#### Node::Output output

Kind: variable

Filtered frame

#### Node::Input inputConfig

Kind: variable

Config to be set for a specific filter

#### std::shared_ptr< ImageFilters > build(Node::Output & input, ImageFiltersPresetMode presetMode)

Kind: function

Build the node. parameters: input: Input for image frames to be filtered; presetMode: Preset mode for image filters return: Shared
pointer to the node

#### std::shared_ptr< ImageFilters > build(ImageFiltersPresetMode presetMode)

Kind: function

Build the node. parameters: presetMode: Preset mode for image filters return: Shared pointer to the node

#### void run()

Kind: function

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void setDefaultProfilePreset(ImageFiltersPresetMode mode)

Kind: function

Set default profile preset for ImageFilters . parameters: mode: Preset mode for ImageFilters .

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
