Image Linear Stretch
The one-trick contrast fix for washed-out inputs
- image
- IMAGE
Image Linear Stretch is a contrast fix with exactly one job: take a washed-out, flat, or under-exposed image and stretch its brightness range so it actually uses the full black-to-white scale. You drop it in front of an img2img or inpainting pass, or anywhere you're feeding a dull reference into the model and getting dull results back. It won't make a bad image good, but it reliably makes a flat one legible, and sometimes that's all a workflow needs.
The name is literal. "Linear stretch" here means percentile clipping followed by a linear remap: it finds the pixel values at your tol_low and tol_high percentiles, then stretches the image so those two points land on black and white. Everything between gets pulled along proportionally; anything outside gets clipped. It's the same trick that numpy's percentile-based contrast stretching has done in image processing for decades, just wrapped as a node.
The knobs
- tol_low / tol_high - the percentile cut points, defaults 0.01 and 0.99. Lower
tol_lowand highertol_highmeans you clip less and stretch gentler; tightening them toward each other makes the stretch more aggressive. - clip - clamps output to 0–1 after stretching (default on). Leave it on; turning it off lets values overflow, which can be a feature for certain math downstream but is usually just an error waiting to happen.
- mode -
per_imagecomputes percentiles across the whole image including all channels;per_channelcomputes them per channel over height and width. Per-channel preserves color balance better when one channel is way off; per-image is the safer default for normal photos.
One output, IMAGE, same shape as the input, ready to wire straight back into whatever you were doing.
Install
Same as every node in this pack - ComfyUI Manager, search "Duanyll Nodepack", install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack
cd duanyll_nodepack && pip install -r requirements.txt
The node itself only needs torch, but the pack's requirements.txt pulls in opencv-python-headless, kornia, insightface, matplotlib, and the Volcengine SDK. You get them all whether you use this node or not.
Where you actually use it
Two patterns worth knowing. First, preprocessing for vision-language models: if you're about to send an image to an LLM that reads fine detail, stretching contrast first often makes text and edges pop in a way that survives the model's downscaling. Second, before inpainting or img2img, where a flat reference produces a flat result - stretch the reference, get better structure preservation.
Honest take: this is a niche utility in a pack nobody's really talking about, and ComfyUI already has a dozen contrast/levels nodes in bigger packs. But it's also dead simple, has exactly the two modes you'd want, and there's no config to get lost in. If you need a percentile stretch and don't want to install an entire image-tools mega-pack for it, this one does the job with zero fuss.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| tol_low | FLOAT | 0.010–1 | — |
| tol_high | FLOAT | 0.990–1 | — |
| clip | BOOLEAN | true | — |
| mode | COMBO | per_image | 2 options: per_image, per_channel |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |