Skip to content

Commit

Permalink
Add alpha matting node (#2292)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Oct 31, 2023
1 parent 6da28a6 commit dff3c12
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 1,106 deletions.
6 changes: 2 additions & 4 deletions backend/src/nodes/impl/rembg/bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
)
from PIL import Image
from PIL.Image import Image as PILImage
from pymatting import estimate_alpha_cf, estimate_foreground_ml
from scipy.ndimage import binary_erosion

from ...impl.image_utils import normalize
from ...utils.utils import get_h_w_c
from .pymatting.estimate_alpha_cf import estimate_alpha_cf
from .pymatting.estimate_foreground_ml import estimate_foreground_ml
from .pymatting.util import stack_images
from .session_factory import new_session

kernel = getStructuringElement(MORPH_ELLIPSE, (3, 3))
Expand Down Expand Up @@ -62,7 +60,7 @@ def alpha_matting_cutout(

alpha = estimate_alpha_cf(img_normalized, trimap_normalized)
foreground = estimate_foreground_ml(img_normalized, alpha)
cutout = stack_images(foreground, alpha)
cutout = np.dstack((foreground, alpha))

cutout = np.clip(cutout * 255, 0, 255).astype(np.uint8) # type: ignore
cutout = Image.fromarray(cutout)
Expand Down
9 changes: 0 additions & 9 deletions backend/src/nodes/impl/rembg/pymatting/LICENSE.md

This file was deleted.

4 changes: 0 additions & 4 deletions backend/src/nodes/impl/rembg/pymatting/__init__.py

This file was deleted.

176 changes: 0 additions & 176 deletions backend/src/nodes/impl/rembg/pymatting/cf_laplacian.py

This file was deleted.

117 changes: 0 additions & 117 deletions backend/src/nodes/impl/rembg/pymatting/cg.py

This file was deleted.

0 comments on commit dff3c12

Please sign in to comment.