SLOHERO Journal Vibe Coding Photoshot Retouch · Part 3 of 24

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

Six panels showing the source portrait, eye and lip outlines, face and body confidence maps, the eye and lip protection mask, and the resulting all-skin mask before refinement
White in the protection map marks the eyes and lips to preserve. The same locations appear dark in the All Skin mask. The panels come from the recorded run. NASA photograph of Eileen Collins via scikit-image

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.

  1. InputSource RGBengine.py · process()The working image has a long edge of at most 1,400 pixels.
  2. ProcessingRun two modelsregions.py · Vision.analyze()Get landmarks and six confidence planes in working-image coordinates.
  3. OutputShared region dataregions.py · Analysis.dataLater tools read the same result within the job.
The 512 × 512 lab portrait fits within the engine’s working size. Its input and analysis coordinates line up directly.

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

  1. InputPixel-space landmarksregions.py · EYES and LIPSTake the contour indices from each face’s point array.
  2. ProcessingBuild the protection maskAnalysis.feature() · cv.dilate()Rasterize, feather, and grow the outlines.
  3. OutputProtected skin coverageAnalysis.skinMultiply the combined skin scores by one minus protection.
Protection of 1 suppresses the skin weight, while fractional protection leaves a soft transition.
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

  1. InputRegion and mask controlstools.py · skin_mask()Pick face, body, or protected all-skin coverage.
  2. ProcessingFeather and scale the weightsblur() · np.clip()Apply optional blur, multiply by sensitivity, and clamp.
  3. OutputGray mask for the editorengine.py · process() and record()Resize to the document and write the mask as a hidden layer when coverage remains.
The engine records Skin Mask as its own layer. The lab exports intermediate masks as PNGs so each decision can be inspected.
RegionStarting coveragePixels at or above 0.5
FaceClass 3 confidence7,414
Outside the faceClass 2 body-skin confidence1,351
All SkinClasses 2 and 3 combined with eye and lip protection8,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

CaseWhat happened
Sensitivity 0Every output mask weight was zero.
Blank frameThe detector returned no landmarks. The protection map was empty and All Skin used the combined class scores.
Two face crops side by sideTwo landmark sets were returned. The feature mask appeared in both halves.
Two full portraits side by sideThe detector returned zero faces for this wider image. Check landmark count before trusting eye and lip protection on a group shot.
Missing or altered modelThe 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

Next · Carry the mask back to the original image

Part 4 follows the mask from the analysis image to the document. We’ll track how mask weights are resized, how alpha and bit depth affect the result, and what the engine must record so an editor can put an RGB patch and its mask back in the right place.

Read Part 2 · Download the exercise