Choose Where the Retouch Can Reach
The skin model gave a pixel inside an eye a face-skin score of 0.915. Would you let a skin correction reach it? In Photoshot’s All Skin mode, a second model locates the eye, and the same pixel becomes black in the exported mask.
Part 2 used a rectangle we typed by hand. This time the image supplies the coordinates. We’ll save the model scores, the facial landmarks, and the final mask separately, then trace that eye pixel through the code. Part 2 · Write Your First Masked PNG
Run the same portrait through both models
Unzip the lab and open PowerShell in that folder on Windows x64. The installer fetches the two versioned MediaPipe model files and checks their SHA-256 hashes. The lab saves its outputs in out/. Download the exercise ZIP · Lab instructions
py -3.10 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe -m service.models
.\.venv\Scripts\python.exe run.py --verify
Start with confidence-face-skin.png, then open protection.png and mask-all-unrefined.png at the same zoom level. The PNGs show the scores as shades of gray. confidence.npy keeps all six float32 planes and landmarks.json keeps the x/y points for each face. Landmarks from this run · Full confidence values
112 · Analyze the source once
The engine derives a working image from the original RGB and builds one Analysis object per job. It holds onto the first result from Vision.analyze(). When the next tool requests landmarks or class scores, it reads that cached result. The cache stays tied to the source image even as earlier tools change the working RGB.
- InputSource RGB
engine.py · process()The working image has a long edge of at most 1,400 pixels. - ProcessingRun two models
regions.py · Vision.analyze()Get landmarks and six confidence planes in working-image coordinates. - OutputShared region data
regions.py · Analysis.dataLater tools read the same result within the job.
Face Landmarker supplies a set of 478 points for each detected face. Photoshot keeps x and y and multiplies the normalized coordinates by the working image’s width and height. The detector is configured for up to eight faces. The Image Segmenter returns one confidence plane for each class across the whole image. Its face-skin plane is shared across any people it finds. Google Face Landmarker · Google Image Segmenter class list
Class 2 is body skin and class 3 is face skin. The other four planes are background, hair, clothing, and accessories. Reading the float score at a pixel preserves the difference between a weak signal and a strong one when we turn it into a mask weight. MediaPipe confidence mask output
113 · Give eyes and lips their own shapes
A face-skin score can be high over an eye or lip. Photoshot takes specific landmark indices around each eye and the outer lips, fills and feathers those shapes, then expands the feathered protection with an elliptical dilation. Each detected face contributes its own eye and lip polygons. Region analysis source
- InputPixel-space landmarks
regions.py · EYES and LIPSTake the contour indices from each face’s point array. - ProcessingBuild the protection mask
Analysis.feature() · cv.dilate()Rasterize, feather, and grow the outlines. - OutputProtected skin coverage
Analysis.skinMultiply the combined skin scores by one minus protection.
protected = cv.dilate(
self.feature([*EYES, LIPS]),
ellipse(max(1, round(self.scale * 0.009))),
)
return np.clip((self.parts[2] + self.parts[3]) * (1 - protected), 0, 1)
Predict the weight at one pixel
Suppose face skin is 0.80 and body skin is 0.05. At an eye edge with protection 0.90, what weight lands in the unrefined All Skin mask?
Check the calculation
The two scores add to 0.85. Protection leaves 0.10 of that sum, so the result is 0.085, or 22 on an 8-bit mask. A point with full protection gives zero. The next section shows what happens when you turn on refinement.
114 · Read what each Skin Mask control does
The region switch chooses the starting plane. The sensitivity slider multiplies its weights from 0 to 2, then clamps them to the 0–1 range. The Refine switch applies a Gaussian blur before sensitivity is applied. Its scale follows the estimated face width. The default settings are All Skin, sensitivity 1, and Refine on. Runnable mask settings
- InputRegion and mask controls
tools.py · skin_mask()Pick face, body, or protected all-skin coverage. - ProcessingFeather and scale the weights
blur() · np.clip()Apply optional blur, multiply by sensitivity, and clamp. - OutputGray mask for the editor
engine.py · process() and record()Resize to the document and write the mask as a hidden layer when coverage remains.
| Region | Starting coverage | Pixels at or above 0.5 |
|---|---|---|
| Face | Class 3 confidence | 7,414 |
| Outside the face | Class 2 body-skin confidence | 1,351 |
| All Skin | Classes 2 and 3 combined with eye and lip protection | 8,107 |
These counts use sensitivity 1 with Refine off. The 0.5 cutoff is for comparing the saved masks. The tool itself uses the continuous weights. The extra protection belongs to All Skin, so Face mode can carry a high weight over an eye. When refinement runs after protection, fractional coverage can return at a soft edge. Face mask · Refined All Skin mask
Check the pixels and the detection failures
In the saved portrait, the sample at (204, 101) landed inside an eye and (223, 145) landed inside the lips. Both had face-skin scores near 0.915. The protection value at each point was 1, so both became zero in the unrefined All Skin mask. Both points also stored 0 in the refined 8-bit PNG. Measured scores and model hashes
| Case | What happened |
|---|---|
| Sensitivity 0 | Every output mask weight was zero. |
| Blank frame | The detector returned no landmarks. The protection map was empty and All Skin used the combined class scores. |
| Two face crops side by side | Two landmark sets were returned. The feature mask appeared in both halves. |
| Two full portraits side by side | The detector returned zero faces for this wider image. Check landmark count before trusting eye and lip protection on a group shot. |
| Missing or altered model | The lab rejected both cases before inference. The model setup uses versioned URLs and SHA-256 to check the files. |
The counts describe these fixtures. To inspect another image, run python run.py --input portrait.png and compare the landmark overlay, the protection map, and the All Skin mask at the eyes and lips. Pinned model URLs and checksums