Color Auto Stretch Contrast (MD)
GIMP's Auto Stretch Contrast, now with a 'keep the colors' switch
- image
- mask
- image
If you've spent any time in GIMP, Auto Stretch Contrast is the "fix every flat scan" button you know. mdColorAutoStretchContrast is that exact operation as a ComfyUI node, and unlike GIMP's one-click version it gives you two switches that control what "stretch" actually does.
The mechanism is simple and worth understanding because the two toggles change the outcome more than you'd think. The node finds the darkest and brightest pixels in the image and remaps the whole range so they span the full [0,1] scale. The question is whether it does that stretch on each RGB channel independently or on all of them together - and that's what keep_colors decides.
The two switches that matter
- keep_colors (default: true) - stretches all three channels by the same factor, preserving color ratios. This is what you want for photos: contrast goes up without the image going weirdly green or magenta. Set it to false and each channel stretches to its own min/max, which usually introduces a color cast - GIMP calls that "per-channel" stretching and it's mostly a creative choice.
- non_linear (default: false) - applies a perceptual, non-linear mapping instead of the plain linear stretch. Linear stretch is fast and exact but can clip or exaggerate; the non-linear path is closer to how the eye sees and tends to look gentler on noisy images.
- image and optional mask round it out. With a mask, the statistics come from the masked region and the effect is blended by mask strength - same pattern as the rest of this pack.
Output is a single image tensor, alpha preserved.
When to reach for it
This sits between the three "auto" fixes in the MdColorMod pack and it's arguably the most useful of them. Auto equalize is aggressive, auto color enhance is about saturation. Stretch contrast is the one that fixes "my image is all in the middle of the histogram" - low-contrast renders, flat lighting, washed-out backgrounds - without inventing color where there was none. Because of the two toggles it's the one that stays controllable: keep keep_colors on for anything realistic, flip it off when you're chasing a stylized look.
For the wider workflow: it's a deterministic post-VAE step, the kind our post-processing notes argue you should do with a $0 node rather than a re-gen or img2img pass. Run it, then a subtle gamma or grain pass, and flat AI output stops looking flat.
Installing
Same as every node in this pack - ComfyUI Manager, search "MdColorMod", or:
cd ComfyUI/custom_nodes
git clone https://github.com/MdONeilsl/ComfyUI-MdColorMod
restart, done. The pack's requirements.txt is empty; it's pure PyTorch, no models, no dependencies. It's new (single commit, July 2026) and GPL-3.0, so if Manager can't find it yet the manual clone is the reliable path. Mask shape caveat from the source: (B, H, W) or (B, H, W, 1) are both accepted here, unlike the equalize node in the same pack.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image tensor. | |
| keep_colors | BOOLEAN | true | Preserve the color ratios when stretching contrast. |
| non_linear | BOOLEAN | false | Use a non-linear (perceptual) stretching method. |
| maskopt | MASK | Optional mask to restrict the adjustment area. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The contrast-stretched image. |