Keep mouth crops independent of teeth settings

This commit is contained in:
Olive Vaughn 2026-09-28 09:06:30 -04:00
parent 7738c4e1c8
commit 7249e73e7c
3 changed files with 34 additions and 12 deletions

View file

@ -42,8 +42,7 @@
(.drawImage ctx image 0 0)
(let [face (detect/detect! model canvas)
ring (when face (mapv #(nth face %) lm/LIPS-INNER))
box (when ring
(interior/crop ring wh (:cavity-erode take/knobs)))
box (when ring (interior/crop ring wh))
measured (if box
(interior/measure take/knobs box
(.getImageData ctx (:x box) (:y box)

View file

@ -10,17 +10,17 @@
:y (+ y (* amount (- (:y p) y)))}) ring)))
(defn crop
"A clamped source-pixel box for the eroded cavity ring. nil means too small
for a useful contrast measurement."
[ring [width height] cavity-erode]
(let [shape (scaled-ring ring (- 1 cavity-erode))
x0 (max 0 (js/Math.floor (* width (reduce min (map :x shape)))))
y0 (max 0 (js/Math.floor (* height (reduce min (map :y shape)))))
x1 (min width (js/Math.ceil (* width (reduce max (map :x shape)))))
y1 (min height (js/Math.ceil (* height (reduce max (map :y shape)))))
"A clamped source-pixel box for the raw inner-lip ring. The box is independent
of teeth settings so its pixels can be reused when those settings change. nil
means too small for a useful contrast measurement."
[ring [width height]]
(let [x0 (max 0 (js/Math.floor (* width (reduce min (map :x ring)))))
y0 (max 0 (js/Math.floor (* height (reduce min (map :y ring)))))
x1 (min width (js/Math.ceil (* width (reduce max (map :x ring)))))
y1 (min height (js/Math.ceil (* height (reduce max (map :y ring)))))
w (- x1 x0) h (- y1 y0)]
(when (and (>= w 5) (>= h 5))
{:x x0 :y y0 :w w :h h :shape shape
{:x x0 :y y0 :w w :h h :shape ring
:source-width width :source-height height})))
(defn- point-in-poly? [points x y]
@ -133,7 +133,8 @@
image-data]
(let [pixels (.-data image-data)
polygon (mapv (fn [p] {:x (- (* (:x p) source-width) x)
:y (- (* (:y p) source-height) y)}) shape)
:y (- (* (:y p) source-height) y)})
(scaled-ring shape (- 1 cavity-erode)))
hist (js/Uint32Array. 256)
luminance (js/Uint8Array. (* w h))
redness (js/Float32Array. (* w h))