> Documentation index for agents: https://docs.rocketride.ai/llms.txt

# image_cleanup

A RocketRide image filter node that prepares incoming images for OCR by
normalizing their format, enhancing contrast, correcting skew, and closing small
gaps in characters. Use it before OCR when scans are noisy, low quality, or
tilted, rather than where downstream processing needs to retain the original
image bytes or color.

## About OpenCV

OpenCV supplies the image operations used by this node. Here it decodes the
normalized PNG, converts it to grayscale, applies blur, contrast enhancement,
rotation, and morphological closing, then encodes the result as PNG.

## What it does

Receives a streamed image on the `image` lane, buffers it until the stream ends,
then emits a cleaned replacement on the same lane. It is a pipeline-only filter:
there are no agent-callable functions or configuration fields. Pick it for an OCR
path that benefits from a grayscale, contrast-enhanced and deskewed image; place
another image node in the path when preserving color or the input representation
matters.

## Lanes

| Lane in | Lane out | Description |
| --- | --- | --- |
| `image` | `image` | Receives an image stream and emits its cleaned PNG replacement. |

## Configuration

This node has no configuration fields. Add it between the image source and the
OCR consumer; it applies the same cleanup sequence to every complete image
stream.

## Notes

### Processing and output

Inputs whose MIME type is not `image/png` are opened with Pillow, converted to
RGBA, and saved as PNG. The cleanup stages then decode the PNG with OpenCV,
convert it to grayscale, apply a 5×5 Gaussian blur and CLAHE contrast
enhancement (clip limit 2.0; 8×8 tile grid), deskew it, and apply morphological
closing with a 2×2 kernel. The output is therefore a grayscale `image/png`.

Deskewing inverts the grayscale image, finds its non-zero pixels, and uses their
minimum-area rectangle to choose a rotation angle. If no such pixels are found,
the angle remains zero. Rotation uses cubic interpolation and replicated image
borders, so edge pixels are extended rather than filled with a constant border.

### Streaming and failures

The node stores every `WRITE` chunk in memory and performs processing only on
`END`; it suppresses the original stream instead of forwarding it alongside the
replacement. It parses the source descriptor received at `BEGIN` and supplies it
when forwarding the cleaned image.

There is no local fallback to the original input. A non-PNG image that Pillow
cannot convert raises `ValueError`; the cleanup stages also raise when OpenCV
cannot decode or encode their PNG data. Use valid, complete image streams and
account for the full image being buffered before selecting this node for very
large inputs.

## Upstream docs

- [OpenCV documentation](https://docs.opencv.org/)

---

<!-- ROCKETRIDE:GENERATED:PARAMS START -->
<!-- Generated by nodes:docs-generate. Do not edit by hand. -->

## Schema

_No configuration fields._

## Dependencies

- `pillow`

## Source

[<svg viewBox="0 0 16 16" width="15" height="15" fill="currentColor" aria-hidden="true" style="vertical-align:-0.15em;margin-right:0.35em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg> View source](https://github.com/rocketride-org/rocketride-server/tree/develop/nodes/src/nodes/image_cleanup)
<!-- ROCKETRIDE:GENERATED:PARAMS END -->
