// カーネル(3×3) const kernel = [ [1, 2, 1], [2, 4, 2], [1, 2, 1] ]; const kernelSum = 16; // ぼかし処理 for (let y = 1; y < h - 1; y++) { for (let x = 1; x < w - 1; x++) { let sum = 0; for (let ky = -1; ky <= 1; ky++) { for (let kx = -1; kx <= 1; kx++) { sum += gray[(y + ky) * w + (x + kx)] * kernel[ky + 1][kx + 1]; } } blurred[y * w + x] = sum / kernelSum; } }