# Mean Shift Filtering

This function block applies mean shift filtering to RGB images to smooth color regions while preserving edges. It is useful for denoising, color segmentation, and preparing images for contour or blob analysis.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`ImageRGB` Input RGB image to be processed.

(here the socket is an input socket)

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`ImageRGB` Filtered RGB image (same type as input).

(here the socket is an output socket)

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Spatial Radius` Slider that controls the spatial neighbourhood used for filtering (smaller = finer detail preserved).\
Range: 1 — 3

`Color Window Radius` Slider that controls the color similarity window (larger = stronger color smoothing).\
Range: 20 — 100

`Maximum Level Radius` Slider that adjusts the number of pyramid levels used internally (higher = more aggressive smoothing, but slower).\
Range: 1 — 5

## ⚙️ Running mechanism <a href="#how-it-runs" id="how-it-runs"></a>

When this block receives an image through the `ImageRGB` input, it applies mean shift filtering using the values set on the three sliders and outputs the processed image through the `ImageRGB` output. Changes to any slider take effect on the next evaluation, so you can tune the parameters interactively while previewing results.

## ✨ Features <a href="#features" id="features"></a>

* Smooths color regions while keeping object edges sharp.
* Reduces noise and small texture details, making segmentation and shape detection easier.
* Real-time parameter tuning via sliders for quick experimentation.

## 📝 Usage recommendations <a href="#usage" id="usage"></a>

1. Feed an RGB image into the `ImageRGB` input.
2. Adjust `Spatial Radius` to control how much local spatial smoothing occurs.
3. Increase `Color Window Radius` to merge similar colors into larger uniform regions.
4. Use `Maximum Level Radius` sparingly — higher values increase processing time.
5. Inspect the result from the `ImageRGB` output in a preview block or the image viewer.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* If your source image is very large and processing is slow, add Image Resizer before this block to reduce image dimensions and speed up processing.
* For noisy inputs, consider a light Blur before mean shift to remove sensor noise without losing important edges.
* After mean shift, use Find Contour or Blob Detector to extract clean object shapes from the smoothed color regions.
* To focus processing on a specific area, crop first with Image ROI Select and feed the cropped image to this block.
* Use HSV Filter or Color Quantizer and Clustering after mean shift to refine color-based segmentation.
* Preview results with Show Image and save interesting frames with Image Logger or Image Write.

(hints above reference complementary function blocks available in the system)

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Slow performance: lower `Color Window Radius` or `Maximum Level Radius`, or reduce image size with Image Resizer.
* Over-smoothed details: reduce `Color Window Radius` and/or `Spatial Radius` to preserve finer features.
* Uneven segmentation across lighting changes: try combining HSV Filter or adjust lighting (capture settings) before processing.
* Unexpected colors or artifacts: visualize intermediate steps with Show Image to check inputs and consider using Blur or Denoising upstream.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/image-transformations/transformation-filters/mean-shift-filtering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
