EllipseForeground

EllipseForeground finds the alpha matte of an image's foreground from a rough ellipse.
It is the reference implementation of a paper. It uses no learned model and no extra annotation: the input is an image and an ellipse.

Read the paper in your browser. It is written in Japanese. Nothing is uploaded.


Install

Python 3.11 or later, with NumPy, SciPy and Pillow. Download the package of the latest release from Releases, unzip it, and install the wheel in it.

python -m pip install ellipse_foreground-X.Y.Z-py3-none-any.whl

Use

This program reads an image, takes an ellipse around the foreground and writes the alpha matte. Calling extract again on the same Analysis with another ellipse reuses the tree built for the image.

import numpy as np
from PIL import Image

from ellipse_foreground import Analysis, Ellipse, Mix

source = np.asarray(Image.open("input.png").convert("RGB"))
analysis = Analysis(source.astype(np.float32) / 255.0, source)
ellipse = Ellipse(center_x=640, center_y=330, radius_x=190, radius_y=300)
alpha = analysis.extract(ellipse, Mix.ADAPTIVE_COLOR)
Image.fromarray(np.rint(alpha * 255).astype(np.uint8)).save("alpha.png")

What it does

Speed and limits

Links