Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(selfie): raise the blur floor to a value real photographs can actually fail
nirholas921a2a024623
diff --git a/src/selfie-gates.js b/src/selfie-gates.jsindex c83103d2d..a79be1635 100644--- a/src/selfie-gates.js+++ b/src/selfie-gates.js@@ -26,10 +26,25 @@* (workers/avatar-reconstruction/eval/robustness.py `blurred`) models the* defect as a Gaussian blur of radius longestEdge/220. BLUR_STDDEV_MIN is* the live-feed equivalent: the Laplacian response stddev of a 64px face- * crop under that degradation drops well below 3.5 while handheld-sharp- * faces sit far above it. SHARPNESS_VAR_MIN = 90 is the same idea at- * still-photo resolution (variance, not stddev, at up to 1024px), the- * threshold src/selfie-refine.js has always applied at submit time.+ * crop. The value is measured, not assumed. Six real portrait photographs+ * were framed as 720x1280 phone selfies and scored through this module's+ * own math, sharp against the benchmark's exact degradations:+ *+ * sharp 22.8 23.4 23.7 27.4 38.3 39.4+ * GaussianBlur r=longest/220 10.6 12.6 13.8 14.0 14.8 15.7+ * GaussianBlur r=10 6.3 6.8 8.2 8.4 8.5 9.4+ *+ * The previous floor of 3.5 sat below every one of those readings, so the+ * gate never fired on any real photograph, however badly blurred: it told+ * users "Sharp" on a frame smeared past recognition. 12 sits in the empty+ * band between the blurred and sharp populations, rejecting every+ * heavily-blurred sample while leaving the least-sharp real face nearly+ * 2x of headroom. The mild benchmark degradation straddles it on purpose:+ * it costs identity stability but is not a reconstruction failure, and+ * over-rejecting a usable capture is worse than accepting a soft one.+ * SHARPNESS_VAR_MIN = 90 is the same idea at still-photo resolution+ * (variance, not stddev, at up to 1024px), the threshold+ * src/selfie-refine.js has always applied at submit time.* - Lighting: the robustness benchmark's `dim` degradation (brightness x0.42,* "indoor evening") lands a typical selfie's mean face luma at the LUMA_MIN* boundary, and the adversarial set's "hard-backlight, face in deep shadow"diff --git a/tests/selfie-gates.test.js b/tests/selfie-gates.test.jsindex 43ee387b7..70f644086 100644--- a/tests/selfie-gates.test.js+++ b/tests/selfie-gates.test.js@@ -40,6 +40,26 @@ describe('grayFaceStats', () => {expect(smooth.blurStddev).toBeLessThan(GATES.BLUR_STDDEV_MIN);});+ it('keeps the blur floor above the blurred population measured on real faces', () => {+ // Measured on six real portrait photographs framed as 720x1280 phone+ // selfies: the worst heavily-blurred reading (GaussianBlur r=10) was+ // 9.4, the least sharp real face read 22.8. A floor outside that band+ // is decoration: it either never fires or rejects usable captures.+ expect(GATES.BLUR_STDDEV_MIN).toBeGreaterThan(9.4);+ expect(GATES.BLUR_STDDEV_MIN).toBeLessThan(22.8);+ });++ it('reports the blown-highlight share of the crop', () => {+ const half = grayFaceStats(grey(16, 16, (x, y) => (y < 8 ? 255 : 128)), 16, 16);+ expect(half.clippedFrac).toBeCloseTo(0.5, 5);+ expect(grayFaceStats(grey(16, 16, () => 128), 16, 16).clippedFrac).toBe(0);+ });++ it('counts only pixels at or above the clip level', () => {+ expect(grayFaceStats(grey(8, 8, () => GATES.CLIP_LEVEL - 1), 8, 8).clippedFrac).toBe(0);+ expect(grayFaceStats(grey(8, 8, () => GATES.CLIP_LEVEL), 8, 8).clippedFrac).toBe(1);+ });+it('handles degenerate sizes without NaN', () => {expect(grayFaceStats(grey(2, 2, () => 50), 2, 2)).toEqual({ luma: 50, blurStddev: 0, clippedFrac: 0 });expect(grayFaceStats([], 0, 0)).toEqual({ luma: 0, blurStddev: 0, clippedFrac: 0 });@@ -128,6 +148,30 @@ describe('gradeFrame', () => {expect(gradeFrame({ ...goodFrontal, luma: GATES.LUMA_MAX }).lumaOk).toBe(true);});+ it('rejects a face blown out in patches even when its mean luma looks fine', () => {+ // Window glare pins part of the face to white while the rest stays in+ // shadow, so the mean lands mid-band. Clipping also *raises* Laplacian+ // response, so neither the luma nor the blur gate can see it.+ const g = gradeFrame({+ ...goodFrontal,+ luma: 130,+ clippedFrac: GATES.CLIPPED_FRAC_MAX + 0.05,+ });+ expect(g.lumaOk).toBe(false);+ expect(g.allPass).toBe(false);+ expect(g.reason).toMatch(/bright|light|window/i);+ });++ it('accepts the specular highlights every real face carries', () => {+ const g = gradeFrame({ ...goodFrontal, clippedFrac: GATES.CLIPPED_FRAC_MAX });+ expect(g.lumaOk).toBe(true);+ expect(g.allPass).toBe(true);+ });++ it('treats a missing clipping measurement as unclipped', () => {+ expect(gradeFrame(goodFrontal).lumaOk).toBe(true);+ });+it('names the yaw fix before the blur fix when both fail', () => {const g = gradeFrame({ ...goodFrontal, yaw: 30, blur: 0 });expect(g.reason).toMatch(/straight on/i);