Files
behind_glass/scripts/test-depth-evidence.mjs
2026-10-06 12:16:46 +09:00

20 lines
1.1 KiB
JavaScript

import assert from 'node:assert/strict';
import { DepthProcessor } from '../src/depth/DepthProcessor.ts';
function texture(values) { return DepthProcessor.fromNormalizedDepth(new Uint8Array(values), values.length, 1); }
const flat = texture(Array(100).fill(128));
assert.deepEqual(DepthProcessor.evidenceRange(flat), [1, 1]);
flat.dispose();
const scene = texture([...Array(60).fill(50), ...Array(25).fill(170), ...Array(14).fill(190), 255]);
const [start, end] = DepthProcessor.evidenceRange(scene);
assert.ok(start < 170 / 255 && end <= 190 / 255, 'face-range depths must contribute below the old 0.8 cutoff; one near outlier must not set the gate');
assert.ok(end > start, 'non-flat evidence range is ordered');
scene.dispose();
for (const nearCount of [10, 60]) {
const bimodal = texture([...Array(100 - nearCount).fill(50), ...Array(nearCount).fill(240)]);
const [low, high] = DepthProcessor.evidenceRange(bimodal);
assert.ok(low < high && high <= 240 / 255, 'two distinct depth layers must not be treated as flat');
bimodal.dispose();
}
console.log('Depth histogram: flat disabled, mid-depth foreground retained, sparse near outlier rejected.');