ImageEn, unit iexHelperFunctions |
|
TIEBitmapHelper.SubtractImageBackground
Declaration
procedure SubtractImageBackground(BackgroundImage: TIEBitmap;
ForegroundImage: TIEBitmap;
Threshold: double = 16;
Shadows: TIEShadowProcessing = iespRemove;
RemoveNoise: Integer = 3;
Feathering: Integer = 0;
DestMask: TIEBitmap = NIL);
Description
Creates a
TIEVisionBackgroundSubtractor to remove the background from an image using a background-only source image.
The
MOG2 algorithm is used to segment the background.
This method creates an alpha channel whereby the background is fully transparent (with partially transparent pixels at subject edges if feathering is enabled).
Parameter | Description |
SubtractorObject | A TIEVisionBackgroundSubtractor object, e.g. initialized in FormCreate using m_backgroundSubtractor := IEVisionLib.createBackgroundSubtractor(); |
BackgroundImage | Image of background only |
ForegroundImage | Image with subject (in front of background) |
Threshold | The cut-off for the MOG2 algorithm. Smaller values return more background. Larger values return more transparency |
Shadows | Whether a detection algorithm is used to detect shadows and either mark them as gray in the DestMask or remove them |
RemoveNoise | Remove any isolated pixels smaller than the specified size (or 0 to skip) |
Feathering | Soften the edges of the subject (or 0 to skip) |
DestMask | If specified, is filled with the removal mask, an ie8g image, where 0 (black) is background, 127 (gray) is shadow and 255 (white) is foreground. Can be NIL if not needed |
This method performs the following tasks:
1.
Creates a background subtractor object
2. Initializes the
MOG2 Segmentation Algorithm
3.
Creates a background-only mask
4. If required, removes the shadows and any excess
noise
5. If required,
feathers the subject edges
Note:
◼You must add the iexHelperFunctions unit to your uses clause
◼Background subtraction requires
IEVision. You will need to
register it before calling the method
◼If attached to a
TImageEnView, it will automatically call
Update
// Using a background image, remove the background from a subject image and output it to IENOutput
IENOutput.IEBitmap.SubtractImageBackground( IENBackground.IEBitmap,
IENSubject.IEBitmap,
trkThreshold.Position,
iespRemove,
3,
updFeathering.Position );