• Remove background from an image using AI-powered segmentation.

    This is the main function for background removal. It supports multiple input formats and provides various processing options including mask-only output, custom backgrounds, and post-processing.

    Parameters

    • data: HTMLImageElement | HTMLCanvasElement | File | Blob | ArrayBuffer

      Input image as File, Blob, ArrayBuffer, HTMLImageElement, or HTMLCanvasElement

    • options: RemoveOptions = {}

      Processing options

    Returns Promise<Blob>

    Promise - Processed image as PNG blob with transparent background

    Example

    // Basic usage
    const fileInput = document.getElementById('file') as HTMLInputElement;
    const file = fileInput.files[0];
    const result = await remove(file);

    // With progress tracking
    const result = await remove(file, {
    onProgress: (info) => console.log(`${info.step}: ${info.progress}%`)
    });

    // Mask only output
    const mask = await remove(file, { onlyMask: true });

    // Custom background color
    const result = await remove(file, {
    bgcolor: [255, 0, 0, 255] // Red background
    });

    Throws

    When input type is not supported

    Throws

    When model fails to generate masks

    Throws

    When browser doesn't support required features (WASM, IndexedDB, etc.)