Table of Contents

Method TryRemoveUniformBackground

Namespace
LMKit.Media.Image
Assembly
LM-Kit.NET.dll

TryRemoveUniformBackground(out ImageBuffer, byte, float)

Attempts to remove a UNIFORM background: the border color estimated by TryDetectBorderBackgroundColor(out Color32, float) is flood-filled from the image border and made fully transparent in a new RGBA32 copy. Only pixels CONNECTED to the border are removed, so an interior region that happens to share the background color (a white shirt on a white sweep, a highlight) keeps its opacity - this is the classic product-shot / logo / scan cutout, and it refuses honestly when the border is not uniform enough instead of guessing at a subject.

public bool TryRemoveUniformBackground(out ImageBuffer result, byte tolerance = 24, float minAccuracy = 0.85)

Parameters

result ImageBuffer

When the method returns true, the RGBA32 cutout (background alpha 0). When the method returns false, null - the source is unsuitable.

tolerance byte

Per-channel distance (0..255) a pixel may sit from the detected background color and still be filled. Defaults to 24.

minAccuracy float

The border-uniformity bar forwarded to TryDetectBorderBackgroundColor(out Color32, float). Defaults to 0.85.

Returns

bool

true when a cutout was produced; otherwise false.

Remarks

O(n) time, one pass of border-seeded flood fill over a byte visit map plus an explicit int stack - no recursion, no per-pixel allocations.

Exceptions

ObjectDisposedException

Thrown if this instance has been disposed.

Share