Pin the mask cases a model benchmark exposed.
A cluster-based rewrite of the model-free estimator was measured against u2netp on seven real 60D frames and came out worse than the border-histogram version (0.214 vs 0.305 mean IoU against the model, best blend weight 0.298), so it was not shipped. The two cases that mattered are now regression tests: a saturated object running off the frame must stay out of the subject, and a dark scene with no clear subject must not be swallowed. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -68,6 +68,60 @@ describe('segmentation', () => {
|
|||||||
expect(background[32 * width + 32]).toBe(0);
|
expect(background[32 * width + 32]).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leaves a saturated object that runs off the frame out of the subject', () => {
|
||||||
|
// Grass around a red mat that spans the whole bottom edge, with the person
|
||||||
|
// sitting in the middle: the mat touches three borders, the person none.
|
||||||
|
const width = 96;
|
||||||
|
const height = 64;
|
||||||
|
const data = new Uint8Array(width * height * 4);
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
const o = (y * width + x) * 4;
|
||||||
|
const mat = y > height * 0.6;
|
||||||
|
const person = x > width * 0.42 && x < width * 0.58 && y > height * 0.35 && y < height * 0.68;
|
||||||
|
if (person) {
|
||||||
|
data[o] = 40;
|
||||||
|
data[o + 1] = 70;
|
||||||
|
data[o + 2] = 180;
|
||||||
|
} else if (mat) {
|
||||||
|
data[o] = 200;
|
||||||
|
data[o + 1] = 30;
|
||||||
|
data[o + 2] = 40;
|
||||||
|
} else {
|
||||||
|
data[o] = 90;
|
||||||
|
data[o + 1] = 130;
|
||||||
|
data[o + 2] = 70;
|
||||||
|
}
|
||||||
|
data[o + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const mask = segmentMask(data, width, height, 'subject');
|
||||||
|
const at = (x: number, y: number) => mask[Math.round(y) * width + Math.round(x)];
|
||||||
|
expect(at(width * 0.5, height * 0.5)).toBe(255);
|
||||||
|
expect(at(4, height * 0.9)).toBe(0);
|
||||||
|
expect(at(width * 0.5, height * 0.95)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not swallow a dark scene with no clear subject', () => {
|
||||||
|
const width = 64;
|
||||||
|
const height = 64;
|
||||||
|
const data = new Uint8Array(width * height * 4);
|
||||||
|
for (let y = 0; y < height; y++) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
const o = (y * width + x) * 4;
|
||||||
|
const streak = y > 30 && y < 33 && x > 8 && x < 52;
|
||||||
|
data[o] = streak ? 220 : 18;
|
||||||
|
data[o + 1] = streak ? 90 : 22;
|
||||||
|
data[o + 2] = streak ? 40 : 34;
|
||||||
|
data[o + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const mask = segmentMask(data, width, height, 'subject');
|
||||||
|
let inside = 0;
|
||||||
|
for (const value of mask) if (value) inside++;
|
||||||
|
expect(inside / mask.length).toBeLessThan(0.6);
|
||||||
|
});
|
||||||
|
|
||||||
it('splits a bimodal score map', () => {
|
it('splits a bimodal score map', () => {
|
||||||
const values = new Float32Array(1000);
|
const values = new Float32Array(1000);
|
||||||
for (let i = 0; i < 500; i++) values[i] = 0.1;
|
for (let i = 0; i < 500; i++) values[i] = 0.1;
|
||||||
|
|||||||
Reference in New Issue
Block a user