pyflink.multimodal.operators.image_remove_background#
- image_remove_background(*columns, alpha_matting=False, alpha_matting_foreground_threshold=240, alpha_matting_background_threshold=10, alpha_matting_erode_size=10, bgcolor=None, model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#
Remove the background from an image using rembg (U2-Net based).
Requires
pip install rembg. This is a pandas batch UDF, but rembg inference is currently invoked per image inside each batch.num_gpus/gpu_typeare forwarded as Flink resource hints; the rembg runtime decides whether the session actually uses GPU execution.- Parameters
*columns – Optional image columns. When provided, the UDF is applied directly instead of returning a factory.
alpha_matting – Enable alpha matting for smoother edge refinement. Default
False.alpha_matting_foreground_threshold – Foreground confidence threshold for alpha matting (0-255). Default
240.alpha_matting_background_threshold – Background confidence threshold for alpha matting (0-255). Default
10.alpha_matting_erode_size – Erosion kernel size for alpha matting refinement in pixels. Default
10.bgcolor – Background fill color as
(R, G, B, A)tuple.None(default) produces a transparent background.model_sharing – Model sharing mode for the rembg session across parallel subtasks.
concurrency – UDF concurrency.
Noneuses the framework default.batch_size – Pandas batch size.
Noneuses the framework default.num_gpus – Fractional GPU count per subtask, e.g.
0.5.Noneruns on CPU.gpu_type – Required GPU type, e.g.
"A10".Noneaccepts any available GPU.
- Returns
A UDF producing decoded image values.
- Example::
>>> # As a reusable variable >>> remove_bg = image_remove_background(alpha_matting=True) >>> df = df.with_columns("nobg", remove_bg(col("img"))) >>> >>> # Inline >>> df = df.with_columns("nobg", image_remove_background(col("img")))