The original image canvas
The mask canvas (grayscale, white=foreground, black=background)
HTMLCanvasElement with transparent background where mask is black
When canvas context creation fails
// Load original image and generate mask
const imageCanvas = imageToCanvas(imageElement);
const maskCanvas = await generateMask(imageCanvas);
// Create cutout with transparent background
const cutout = naiveCutout(imageCanvas, maskCanvas);
// Display result
document.body.appendChild(cutout);
Apply naive cutout by compositing image with mask.
Creates a new canvas with the original image where the mask is applied as the alpha channel. White areas in the mask become opaque, black areas become transparent. This is the core function for background removal.