Method RemoveBackground
- Namespace
- LMKit.Segmentation
- Assembly
- LM-Kit.NET.dll
RemoveBackground(ImageBuffer, CancellationToken)
Removes the background from an image synchronously.
public ImageBuffer RemoveBackground(ImageBuffer image, CancellationToken cancellationToken = default)
Parameters
image
ImageBufferThe input image buffer.
cancellationToken
CancellationTokenA token to monitor for cancellation requests.
Returns
- ImageBuffer
An ImageBuffer containing the image 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 = backgroundDetector.RemoveBackground(input);
output.SaveAsPng("D:\\output.png");
Exceptions
- Exception
Rethrows inner exceptions from async operations.