Photoshot Retouch development journal · 05

Vibe coding Photoshot Retouch, Part 5 — Heal red blemishes and dark spots separately

I used vibe coding to build a Heal tool with two controls. One reduces a small red blemish. The other changes a dark spot only when you choose to enable it. Predict both outputs before you run the same patch through the first and current implementations.

Run the same checkpoint

Unzip the lab and open PowerShell in its lab folder. The verified environment was Windows x64 with Python 3.10.6, NumPy 2.2.6 and OpenCV 5.0.0.

py -3.10 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements-lock.txt
.\.venv\Scripts\python.exe finished\reproduce_heal.py

Start with start/settings.json, then read the archived start/heal_20261108.py and the current finished/service/tools.py. The script generates a 240 × 180 fixture with target and protected regions, renders all 12 strength runs into results/ and writes heal-checks.json. The main matrix uses a fixed skin region and needs only the installed Python packages. Download the lab · Experiment record

1. Find local redness and darkness inside skin

Part 3 supplied face and skin regions. Part 4 added ordered tool execution and patch export. Here the same engine runs heal() on the working image and handles the output mask. The public Retouch4me Heal examples show local blemish cleanup with attention to skin texture. That observable behavior informed the original checklist. This chapter revisits items 52, 53 and 57 for routing, layer output and strength. Retouch4me Heal · Series checklist

tools.lab() converts float32 sRGB into L*, a* and b*. L* measures lightness. A positive local deviation in a* is the red branch’s main cue. The branch compares redness with nearby skin at two radii and adds a small darkness cue. It erodes the skin mask and subtracts a dilated brow mask first. Analysis.skin already protects eyes and lips. The mole branch uses the gap between blurred and actual lightness and reduces coverage in strongly red areas.

spots() thresholds the response, groups neighboring pixels with OpenCV’s eight-connected components, rejects components outside area and shape limits, dilates the survivors and feathers them against the supplied coverage. An illustrative positive redness residual of 5 and darkness residual of 10 give 5 + 0.15 × 10 = 6.5, which clears the red threshold of 3.2. Coverage and component geometry still have to pass.

52 · Route the selected Heal operation

  1. Inputservice/api.py · validate()
    Current RGB, ordered tool ID and two values in [0,1].
  2. Processingservice/engine.py · process() and service/regions.py · Analysis.skin
    Build the shared analysis and pass the working RGB, skin and options to tools.heal().
  3. Outputservice/tools.py · heal()
    Return candidate RGB and a single float mask for the current stack entry.
In the shared engine, an applied correction updates the image passed to the next operation.
red = np.maximum(redness - weighted(redness, support, scale * 1.7),
                 redness - weighted(redness, support, scale * 3.0))
core = spots(red + 0.15 * dark, interior, 3.2, 3,
             max(12, scale ** 2 * 36), max(1, round(scale * 0.25)))

2. Restore the two candidates differently

In the original 8 November 2026 snapshot both masks fed one local inpainting operation. The 9 November Heal v2 snapshot gives red candidates a larger allowed area and a separate reconstruction. Its heal() matches the function in the current checkout. Both snapshots ran through the same fixture, region input and current encoder for the comparison. Snapshot provenance

For a red candidate, heal() excludes the expanded spot from its neighborhood, estimates low-frequency a* and b* from surrounding skin, and adjusts the source L* with a bounded low-frequency correction. A neighborhood coverage test attenuates the mask when too little clean skin surrounds the spot. The calculation carries fine lightness variation forward so this branch can reduce redness while leaving visible texture.

For a dark candidate, fill() calls OpenCV Telea inpainting per float32 RGB channel wherever the hard mask exceeds 0.2. It clips the candidate to an adjacent source color range. heal() weights this result with moles. The current mole branch still has its own narrower area limit and confidence requirement. OpenCV Telea source

for channel in (1, 2):
    cleaned[..., channel] = blur(values[..., channel] * neighbors, radius) / normalization
base = blur(luminance * neighbors, radius) / normalization
low_detail = blur(luminance, max(0.75, scale * 0.32))
lift = 4.5 + 12 * ramp(red, 4, 13)
cleaned[..., 0] = np.clip(luminance + np.clip(base - low_detail, -4.5, lift), 0, 100)

3. Set strengths and return an editable patch

The two options accept 0 through 1. At default settings, the red mask is weighted by 0.6 and mole repair is disabled. Where both branches produce a mask, the larger weight is used and a stronger mole mask chooses the inpainted RGB. Each Heal request can return one edit layer. That layer is encoded at the original RGB bit depth with an 8-bit mask.

57 · Set the strength before generating the layer

  1. Inputservice/tools.py · TOOLS["heal"]
    pimples defaults to 0.6. moles defaults to 0.
  2. Processingservice/tools.py · heal()
    Scale each branch’s mask. In overlaps, the stronger mole mask selects its repaired RGB; the combined mask uses the larger weight.
  3. Outputservice/engine.py · encode() and plugin/photoshop.js · apply()
    Store an 8-bit mask; the integration creates a Normal layer with editable opacity in Photoshop.
The engine options are applied before one patch is written. A later opacity adjustment acts on the complete layer. The Photoshop handoff is source-traced in this experiment.

53 · Give the editor a separately editable result

  1. Inputservice/tools.py · heal()
    Candidate RGB and weighted mask for one Heal request.
  2. Processingservice/engine.py · process() / record()
    Restore source coordinates, quantize the mask and crop it with OpenCV.
  3. Outputservice/api.py · result() / asset()
    Return one Normal Heal patch with RGB, mask and bounds when pixels change.
The local replay opens the emitted assets and blends them in source coordinates.

OpenCV supplies Lab conversion, region measurements, blurring and inpainting. NumPy supplies arrays for the masks and pixel arithmetic. Photoshot defines which regions are eligible, the two reconstruction rules and how the editor receives them. OpenCV connected components · NumPy source

4. Measure the same crop at each setting

Aligned synthetic crops show the input, the first Heal result with the red target unchanged, and the current result with the red target softened.
Left to right, original fixture, first Heal at 1.0, current Heal at 1.0. Mole repair is 0 throughout. The red and dark marks stay in the same coordinates for comparison.
ComparisonMeasured on the supplied fixture
Red ROI, mole control 0Mean a* bias from the clean reference was +23.05 before processing. The first version stayed at +23.05 at 1.0. The current version measured +9.13 at 0.6 and −0.12 at 1.0.
Fine lightness detailAt 1.0, the high-pass L* pattern in the red target correlated 0.977 with the clean reference. Its standard deviation was 0.418 versus 0.535 in the clean reference. Pattern and amplitude are separate measurements.
Dark spotRed-only correction left its encoded pixels unchanged. With the mole control at 1, the remaining lightness deficit was 9.19 from an initial 24.05. The red target stayed unchanged in the mole-only run.
Protected and difficult regionsThe first version changed the brow test mark by up to 60 RGB codes. The current version retained the sampled brow, eyes, lips and off-skin test marks. A larger synthetic red mark missed the current detector. Flat skin and settings 0/0 produced no visible patch.
Asset replayThe 16-bit fixture reassembled from layer and merged assets with maximum final integer difference of 0. The file mask remained 8-bit.

To check the real analysis path, I also ran both versions with MediaPipe CPU regions on the 512 × 512 NASA astronaut sample. At 0.6/0 they returned one Heal layer each, covering 48 and 2,079 mask pixels respectively. Mask size measures where work happened. The supplied experiment record separates that observation from the synthetic texture metric and from historic video frames. Read the evidence and scope

This chapter checks the local Python engine and its result files. Photoshop PSD save, reopen and Undo are editor-level checks. Part 6 examines a different problem, local shine.