function maskImage(pixels, mask) {
"Mask the image by replacing each pixel in the person segmentation with a randomly selected nearby pixel"
let maskPixels = mask.data
for (let ix = 0; ix < maskPixels.length; ix++) {
let [x_, y_] = ixToCoords(4*ix, mask.width)
if ((target == "PEOPLE" && (maskPixels[ix] != -1)) ||
(target == "HEADS" && maskPixels[ix] in [0,1])) {
pixels = maskPixel(pixels, x_, y_)
}
}
return pixels
}