Skip to content

Dehaze is far too strong: haze estimate treats ordinary tones as haze (−0.8 EV at +50, black halos from +10) #1237

Open

Description

@mattsivak

Dehaze is far too strong and isn't usable at normal values: even +20–30 darkens the whole photo, crushes shadows to black and draws dark halos around bright areas. The cause is how haze is estimated, not just the slider gain.

Where

  • crates/pipeline/src/finish.rs (the // --- dehaze (scene linear) block)
  • crates/pipeline/src/local.rs: the haze plane is gaussian(dark_of(..)) with sigma = 2 % of the long edge; airlight = 99.5th percentile of that plane.

This code hasn't changed since M0.4 and was tuned by eye.

Why it's too strong

  1. Ordinary tones count as haze. The dark-channel prior relies on a minimum over a patch, which is about 0 in haze-free areas. We use a Gaussian blur of the per-pixel min(r,g,b). For neutral or muted pixels that's roughly the pixel's own brightness, so t = 1 − 0.95·s·d subtracts the brightness itself. At +100 every tone below the airlight is scaled by about 0.05 (−4.3 EV).
  2. Halos. The wide blur carries bright sky into the foreground's haze estimate, so v − A·(1 − t) goes negative and the .max(0) clips it. A shadow pixel (0.05) beside bright sky (blurred d = 0.7, A = 0.8) clips to pure black at +10.
  3. No gentle range. +100 maps to the prior's maximum (ω = 0.95, t floor 0.12) and the slider scales linearly. Negative dehaze blends up to 70 % toward 0.9·A, which washes the photo out.

Numbers

Simulated: brightness change of a neutral tone sitting in a neighbourhood of the same tone (A = 0.8):

tone +10 +25 +50 +75 +100
0.05 −0.14 EV −0.37 −0.89 −1.73 −4.23
0.18 −0.11 −0.31 −0.77 −1.55 −3.97
0.40 −0.07 −0.21 −0.54 −1.16 −3.39

Measured: lightcraft-cli render docs/images/grid-pd.jpg --size 900 --set effects.dehaze=N (8-bit luma):

dehaze mean median p90 pixels < 4
0 40.9 36 85 6.3 %
+25 33.6 26 77 14.4 %
+50 26.7 11 67 26.8 %
+100 15.0 0 31 73.8 %

docs/images/ba-tetons.jpg at +30 visibly crushes the mid-greys to black, with dark halos around bright edges.

Proposed fix

  • Estimate haze from a min-filter (patch) dark channel normalised by the airlight per channel, refined with the guided filter, instead of a Gaussian average.
  • Keep haze-free shadows at t ≈ 1, so dehaze stops darkening them.
  • Ease the slider response in so low values stay subtle, and hold midtone exposure steady.
  • Re-check negative dehaze.
  • This changes how existing edits render, so ship it as a new process version (docs/process-versions.md) and keep V1 as it is. Measure against Lightroom exports with the single-slider tool from LR-BEHAV-RENDER-FIDELITY: tools/render_fidelity.py measures single-slider responses against your own Lightroom exports #1181 where possible.

Related: #1146 (accuracy in zoom windows), LR-BEHAV-RENDER-FIDELITY, LR-EDIT-EFFECTS-DEHAZE (✅ in the checklist; should be 🟡 until fixed).

Activity

  1. mattsivak commented on Oct 12, 2026

    @mattsivak
    ContributorAuthor

    I am working on this: a reworked dehaze (patch dark channel + guided refinement, gentler slider response, exposure held steady) shipped as a new process version so existing edits keep rendering as before. A PR will link back here.

  2. mattsivak commented on Oct 12, 2026

    @mattsivak
    ContributorAuthor

    Research summary and fix plan

    Why the current Dehaze is too strong

    The current code (crates/pipeline/src/finish.rs:448-461, local.rs, GPU mirror in finish.wgsl) follows the same physical haze model as everyone else: I = J·t + A(1−t). Four places differ from the reference method (He et al., dark channel prior) in ways that make it far too harsh:

    Today Reference method Effect
    Gaussian blur of the darkest channel min(r,g,b), σ = 2 % of the long edge Patch min filter (≈1.2 % of the long edge) of min_c(I_c/A_c) Bright sky bleeds into nearby shadows, which clip to black from about +10
    Airlight is a scalar (99.5th percentile) RGB airlight from the top 0.1 % of the dark channel Colour channels aren't normalised, so casts appear
    No refinement (the README's "guided refinement" claim isn't true) Guided filter Halos
    Linear ω = 0.95·amount, t ≥ 0.12, no exposure compensation (made for full-strength dehazing, not a slider) Up to ×8 amplification and collapsed midtones

    Measured on a test JPEG at +0 / +25 / +50 / +100:

    • median brightness: 36 / 26 / 11 / 0;
    • pixels at pure black: 6.3 % / 14.4 % / 26.8 % / 73.8 %.

    How other apps behave (public docs and reviews only)

    • Lightroom / ACR: a physical haze model with large-scale contrast. +100 is gritty but usable; it never goes black. Some darkening and a cool, saturated shift are accepted. The common complaints are colour casts that change with the amount, amplified vignetting, and noise at high values.
    • Capture One: gentler, with a haze-colour ("Shadow Tone") picker.
    • darktable and RawTherapee: the same physical model, with strength and distance or depth controls.
    • DxO ClearView: local contrast only.
    • Affinity and HitFilm: both ship an exposure-correction control, which confirms haze removal shifts exposure.

    Users expect:

    • +20..30 to be a natural clean-up, +50 strong but usable, and +100 strong but not black;
    • midtones that roughly hold;
    • a colour shift that stays the same as the amount changes;
    • negative values that add a light, near-neutral veil.

    Plan: a new process version (V3)

    V1 and V2 edits keep rendering the same pixels; new edits get V3.

    Haze map, built once per image from a fixed 1024 px proxy of the whole frame, so preview, export and zoomed renders match:

    1. Use a gamma encoding, so the map doesn't depend on exposure.
    2. RGB airlight A: the top 0.1 % of the dark channel, then the brightest pixel among them. Pull it 50 % toward neutral.
    3. Per-pixel normalised dark g = min_c(e_c/A'_c), then a patch min filter (r ≈ 1.2 % of the long edge, O(1) van Herk/Gil-Werman).
    4. Refine with a guided filter guided by g (r ≈ 3.5 %, ε = 1e-3). Cache only its a/b coefficients.
    5. A small exposure-compensation lookup table per slider amount, measured on the proxy.
    6. Cache key includes the process version (today's lin_key doesn't).

    Per pixel (CPU finish.rs and GPU finish.wgsl):

    • d̃ = a·g + b, with a/b sampled bilinearly from the proxy.
    • Positive amounts:
      • t = max(1 − 0.95·k^1.5·d̃, lerp(1, 0.25, k)), so it eases in gently and amplifies no more than ×4;
      • sky tolerance (K ≈ 0.15);
      • recover in linear light;
      • restore about 65 % of the exposure loss;
      • blend 30 % of the input chroma back.
    • Negative amounts: a veil toward A', heavier where d̃ is high.
    • Mask Dehaze stays additive to the global amount, clamped to ±1.
    • No panics: every division is guarded and NaN falls back to the input pixel.

    Two side benefits: zoomed renders no longer need a wider margin, and the GPU's mid-render airlight readback goes away for V3.

    Acceptance targets

    Amount Median shift Pixels clipped to black
    +25 0 to −0.2 EV ≤ +1 % over the original
    +50 −0.2 to −0.5 EV ≤ +3 %
    +100 −0.4 to −0.9 EV ≤ +8 %

    Also required:

    • no black halo wider than 2 px at bright edges;
    • hue drift of neutral greys under 2° between +25 and +100;
    • a flat grey image unchanged;
    • preview, export and windowed renders agree within 1/255 mean and 3/255 max;
    • CPU and GPU agree within the existing equivalence bounds;
    • the haze map takes ≤ 15 ms per image, and a slider tick adds ≤ 2 ms at 2.5 MP.

    Steps (one commit each, cargo xtask ci green)

    1. Honest docs: downgrade LR-EDIT-EFFECTS-DEHAZE to 🟡, fix the README claim, update docs/gaps.md.
    2. Measurement tool: an example that prints EV shift, black clipping, halo width and hue drift, plus a procedural hazy scene. It records V1 as the baseline.
    3. V3 scaffold: add Process::V3 as LATEST, plus process-version docs and tests.
    4. Haze map on the CPU: raster min filter and pipeline/src/haze.rs, wired into Plan.
    5. V3 per-pixel stage on the CPU: tests_dehaze.rs (acceptance bands, halo, flat grey, NaN, V1 unchanged, window vs whole, masks).
    6. GPU mirror: add V3 cases to equivalence.rs.
    7. Tune by eye in the app: check screenshots and cargo xtask bench.
    8. Close out: restore ✅ only if every target passes, update the docs, open a PR that closes this issue.

    Out of scope for now:

    • an airlight field for scenes with the sun or a large sky;
    • a manual haze-colour picker;
    • iterative methods (Meng, Berman) as an export-quality option.

    Open question: the "+50 darkness" band is an estimate. Before final tuning, we'll check it against Lightroom on a photo we own, by observation only.

  3. mattsivak commented on Oct 12, 2026

    @mattsivak
    ContributorAuthor

    Update: @emmertex's #1283 fixes this too, and it was up first. It's the smaller change, so that's the one to land. I've reviewed it with before/after renders on four photos and a passing GPU test run on Metal: #1283 (review)

    My draft #1286 is on hold. Once #1283 is merged, I'll trim it down to a small follow-up on top of it:

  4. David990 commented on Oct 14, 2026

    @David990

    Version 0.8: Texture, Clarity and Dehaze behave like a 1990s sharpen filter just using a different radii. Lightroom's Texture, Clarity and Dehaze operate differently and produce very different results. The current LightCraft implementation butchers the photos.

  5. unemployedCHAD commented on Oct 25, 2026

    @unemployedCHAD

    not sure if this is the same thing, but dehaze feels off for me too, kinda like @David990 said. pushing it up mostly just adds contrast, and pulling it down doesn't give that foggy look like in lightroom. on 0.14.0. thanks for working on this!

  6. vvzvlad commented on Nov 16, 2026

    @vvzvlad

    Negative Dehaze washes photos out compared with Lightroom. I measured this on 0.21.1 with a photo imported from a Lightroom Classic catalog: a Canon JPEG, process 15.4, with Contrast −36, Highlights −64, Shadows +51, Whites +32, Blacks −40, Dehaze −27, Clarity +16 and a custom point curve. I compared Lightroom's own export with LightCraft's app.export, both sRGB at 1440 px, using the 2nd-percentile L* (CIELAB) as the black point:

    render black point L*
    Lightroom 5.1
    LightCraft, as imported 15.7
    LightCraft, Dehaze 0 7.1
    LightCraft, Contrast 0 13.3
    LightCraft, Shadows 0 12.2
    LightCraft, Blacks 0 16.5

    Nearly all of the difference comes from Dehaze −27. Blacks −40 hardly matters under it: setting Blacks to 0 moves the black point by only 0.8. In my catalog, 477 of 11,260 photos have a negative Dehaze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions