fix(inpaint): zero out mask in LaMa FFC input tensor and lock mobile col-main chip row to 52px

This commit is contained in:
2026-10-17 12:18:30 +07:00
parent 194a89f89a
commit 7c6baa6319
4 changed files with 66 additions and 16 deletions
+9 -7
View File
@@ -145,7 +145,9 @@ export async function runServerInpaint(
const resizedImg = resizeBilinear(rawRgb, w, h, scaledW, scaledH, 3);
const resizedMask = resizeBilinear(rawMask, w, h, scaledW, scaledH, 1);
// Pad into side x side buffer with edge replication for image and 0 for mask
// Pad into side x side buffer with edge replication for image and 0 for mask.
// CRITICAL FOR LAMA FFC: X_input = I * (1 - M). The pixels inside the mask must be
// zeroed out (0.0) before passing into the network to eliminate frequency resonance starbursts.
const inImage = new Float32Array(3 * side * side);
const inMask = new Float32Array(side * side);
@@ -156,13 +158,13 @@ export async function runServerInpaint(
const dstIdx = y * side + x;
const srcIdx = sy * scaledW + sx;
inImage[dstIdx] = resizedImg[srcIdx];
inImage[side * side + dstIdx] = resizedImg[scaledW * scaledH + srcIdx];
inImage[2 * side * side + dstIdx] = resizedImg[2 * scaledW * scaledH + srcIdx];
const isHole = (y < scaledH && x < scaledW && resizedMask[srcIdx] > 0.15) ? 1.0 : 0.0;
inMask[dstIdx] = isHole;
if (y < scaledH && x < scaledW) {
inMask[dstIdx] = resizedMask[srcIdx] > 0.15 ? 1.0 : 0.0;
}
const keep = 1.0 - isHole;
inImage[dstIdx] = resizedImg[srcIdx] * keep;
inImage[side * side + dstIdx] = resizedImg[scaledW * scaledH + srcIdx] * keep;
inImage[2 * side * side + dstIdx] = resizedImg[2 * scaledW * scaledH + srcIdx] * keep;
}
}