Vibe coding Photoshot Retouch, Part 6 — Mattifier for local skin shine
Vibe coding a Mattifier began with a check I could see on a portrait. The forehead and nose should lose some shine while the nearby cheek keeps its lightness. I tested the current Photoshot Retouch code against a simple comparison that reduces the lightness of all selected skin.
Run the same checkpoint
Unzip the lab and open PowerShell inside lab. Use Windows x64 and Python 3.10. The supplied start code is a uniform skin-darkening comparison. The finished code invokes the current Mattifier and shared engine with the same input.
py -3.10 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements-lock.txt
.\.venv\Scripts\python.exe finished\reproduce_mattifier.py
start/settings.json fixes the 256 × 192 test image and strengths. Expect input/shine.png and ROI masks, a side-by-side comparison, Normal layer assets and results/mattifier-checks.json. The synthetic test runs with the pinned Python packages. The optional portrait check adds the same MediaPipe models used in Part 3. Download the lab · Experiment record
1. Estimate the lightness of nearby skin
Retouch4me shows before-and-after images of reducing oily or flash-lit highlights. That public result is the behavior I used as a reference. The original Photoshot research checklist links observed editing behavior to implementation and tests. This chapter revisits items 52, 57 and 53 for tool order, strength and a separate result layer. Retouch4me Mattifier · Checklist and series introduction · Part 5, Heal
Part 5 used Lab color and local lightness to distinguish a red blemish from a dark spot. Mattifier also begins with float32 sRGB working pixels of shape height × width × 3. It takes the Lab L* plane, then estimates diffuse light by blurring lightness weighted by eligible skin and dividing by blurred skin weights. That keeps dark background pixels from pulling the estimate down across the face boundary.
52 · Pass the current image into the selected tool
- Input
service/api.py · validate()
Ordered tool ID, validatedblendand job pixel format. - Processing
service/engine.py · process(),service/regions.py · Analysis.skin
Give Mattifier the current working RGB, eligible skin and analysis scale. - Output
service/tools.py · mattifier()
Return candidate RGB and float coverage. The engine composites the correction before the next tool runs.
def weighted(values, mask, radius):
return blur(values * mask, radius) / np.maximum(blur(mask, radius), 0.001)
light = lab(rgb)[..., 0]
radius = max(2, region.scale * 0.028)
diffuse = weighted(light, region.skin, radius * 2.4)
With the lab's face scale of 200, radius is 5.6. The neighborhood estimate uses Gaussian σ 13.44. The local lightness image uses σ 1.68.
2. Reduce the bright residual
Subtract the diffuse estimate and a 2-L* threshold from the more narrowly blurred lightness. Keep only the positive residual and cap it at 22. The candidate subtracts 80% of that value at full strength. A separate ramp multiplies the mask by zero at source L* 51 or below and by one at 78 or above, rising linearly between them. The existing skin weights multiply that ramp.
shine = np.clip(blur(light, radius * 0.30) - diffuse - 2, 0, 22)
return luminosity(rgb, -shine * p["blend"] * 0.8), region.skin * ramp(light, 51, 78)
For a pixel whose narrow estimate is 82 and diffuse estimate is 70, the residual is 82 − 70 − 2 = 10. At default strength 0.5 the candidate is 4 L* lower. If the original pixel is 81 L* and fully within eligible skin, the ramp is 1. The resulting patch is about four lightness units lower before RGB encoding. At an original lightness of 64.5 the ramp would be 0.5 and the layer would blend half the RGB change.
57 · Use tool strength to scale the highlight correction
- Input
service/tools.py · TOOLS["mattifier"]blendis 0–1 and defaults to 0.5. - Processing
service/tools.py · mattifier() / luminosity()
Scale the candidate's lightness reduction. Keep the separate skin and brightness gate as coverage. - Output
service/engine.py · process()
Apply the weighted candidate. The Photoshop adapter's Normal-layer opacity acts on the exported edit afterward.
OpenCV handles conversion to Lab, Gaussian filtering and conversion back to RGB. NumPy handles the threshold, limits and gate. The choice of radii, floor and cap belongs to Photoshot's own implementation. OpenCV color conversions · OpenCV Gaussian filtering source · NumPy source
3. Save pixels and a mask that can be reapplied
The common engine applies its negligible-difference filter before exporting. It stores only the cropped region with a material correction, with Normal RGB at the job's input bit depth and one byte of mask per crop pixel. A mask can cover bright skin in the tool's raw return while the engine finds zero encoded correction and exports no layer. For RGBA, fully transparent and partially transparent source pixels are excluded from the exported correction.
53 · Return a separate, editable Mattifier patch
- Input
service/tools.py · mattifier()
Candidate RGB and skin-weighted lightness gate. - Processing
service/engine.py · process() / record()
Filter negligible RGB differences, quantize coverage and crop the remaining mask. - Output
service/api.py · result() / asset()
Return the patch rectangle and RGB with a byte mask.plugin/photoshop.js · paint()places both at the same offset.
The uniform comparison applies the same requested L* reduction to all selected skin, using the same encoding. I set the amount from the measured forehead drop of the default Mattifier pass to compare similar reductions at the target area.
4. Compare the forehead, nose and cheek with the same input

| 8-bit synthetic result | Mean forehead ΔL* | Mean nose ΔL* | Mean cheek ΔL* | Mask pixels |
|---|---|---|---|---|
| Mattifier 0 | 0 | 0 | 0 | 0 |
| Mattifier 0.5 | −5.13 | −5.83 | 0 | 592 |
| Mattifier 1 | −10.17 | −11.55 | 0 | 593 |
| Uniform skin reduction | −5.23 | −5.31 | −5.22 | 23,189 |
The bright region outside the skin mask and all other pixels outside it were unchanged. A skin fixture with a gentle lightness gradient yielded no patch. To test a false positive, I painted a bright matte mark inside the skin mask. It lost 10.84 L* at full strength, even though it represents a color mark without gloss. Local brightness by itself cannot distinguish a reflection from pale material. Use the exported mask to inspect what was changed.
The 16-bit RGBA case rebuilt layers and merged with zero final integer difference and preserved the transparent and partial-alpha samples. The NASA portrait run exercised actual MediaPipe CPU segmentation. At strength 0 it emitted one layer with a one-pixel mask because of the Lab-to-RGB round trip. The 8-bit rendered pixels were unchanged and merged mode returned no layer. Photoshop save, reopen and Undo are separate editor checks. Full synthetic measurements · Portrait measurements
Part 7 moves from isolated bright spots to the wider light and dark variations targeted by Dodge & Burn.