Class BackgroundDetection
- Namespace
- LMKit.Segmentation
- Assembly
- LM-Kit.NET.dll
Provides background removal functionality for images using a segmentation model.
public sealed class BackgroundDetection
- Inheritance
-
BackgroundDetection
- Inherited Members
Examples
Example of removing the background from an image:
using LMKit.Media.Image;
using LMKit.Segmentation;
// Load the model (U²-Net for segmentation)
var backgroundDetector = new BackgroundDetection(
LM.LoadFromModelID("u2net"));
// Load input image
var inputImage = ImageBuffer.LoadAsRGB("D:\\input.png");
// Remove background asynchronously and save result
var outputImage = backgroundDetector
.RemoveBackgroundAsync(inputImage)
.Result;
outputImage.SaveAsPng("D:\\output.png");
Constructors
- BackgroundDetection(LM)
Initializes a new instance of the BackgroundDetection class.
Methods
- GetBackgroundMask(ImageBuffer, CancellationToken)
Generates the background mask of an image synchronously.
- GetBackgroundMaskAsync(ImageBuffer, CancellationToken)
Generates the background mask of an image asynchronously.
- RemoveBackground(ImageBuffer, CancellationToken)
Removes the background from an image synchronously.
- RemoveBackgroundAsync(ImageBuffer, CancellationToken)
Removes the background from an image asynchronously.