• 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.

    Parameters

    • imageCanvas: HTMLCanvasElement

      The original image canvas

    • maskCanvas: HTMLCanvasElement

      The mask canvas (grayscale, white=foreground, black=background)

    Returns HTMLCanvasElement

    HTMLCanvasElement with transparent background where mask is black

    Throws

    When canvas context creation fails

    Example

    // 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);