Table of Contents

Method RemoveBackgroundAsync

Namespace
LMKit.Segmentation
Assembly
LM-Kit.NET.dll

RemoveBackgroundAsync(ImageBuffer, CancellationToken)

Removes the background from an image asynchronously.

public Task<ImageBuffer> RemoveBackgroundAsync(ImageBuffer image, CancellationToken cancellationToken = default)

Parameters

image ImageBuffer

The input image buffer.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<ImageBuffer>

A task that represents the asynchronous operation. The task result contains the ImageBuffer without background.

Examples

using LMKit.Media.Image;
using LMKit.Segmentation;

// Load the model (U²-Net for segmentation)
var backgroundDetector = new BackgroundDetection(
    LM.LoadFromModelID("u2net"));

var input = ImageBuffer.LoadAsRGB("D:\\input.png");
var output = await backgroundDetector.RemoveBackgroundAsync(input);
output.SaveAsPng("D:\\output.png");