def mian(file_path):
    inference.main(file_path)
    try:
        cutout(file_path, "trimap.png", "test.png")
        print('=' * 40 + '>Successfully!')
        os.remove('trimap.png')
        os.remove('pha.png')
    except:
        print('Erro')
Exemple #2
0
from pymatting import cutout

cutout(
    # input image path
    "../data/lemur/lemur.png",
    # input trimap path
    "../data/lemur/lemur_trimap.png",
    # output cutout path
    "lemur_cutout.png",
)
Exemple #3
0
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')

from pymatting import cutout

cutout(
    # input image path
    "lemur.png",
    # input trimap path
    "lemur_trimap.png",
    # output cutout path
    "lemur_cutout.png")
Exemple #4
0
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')

from pymatting import cutout

cutout(
    # input image path
    "1.png",
    # input trimap path
    "2.png",
    # output cutout path
    "3_cutout.png")
Exemple #5
0
    size, Image.BOX)

# convert to numpy array in range [0, 1]
u2net_alpha = np.array(u2net_alpha)

# guess likely foreground/background
is_foreground = u2net_alpha > 240
is_background = u2net_alpha < 10

# erode foreground/background
size = 31
structure = np.ones((size, size), dtype=np.int)
is_foreground = binary_erosion(is_foreground, structure=structure)
is_background = binary_erosion(is_background,
                               structure=structure,
                               border_value=1)

# build trimap
# 0   = background
# 128 = unknown
# 255 = foreground
trimap = np.full(u2net_alpha.shape, dtype=np.uint8, fill_value=128)
trimap[is_foreground] = 255
trimap[is_background] = 0

Image.fromarray(trimap).save("trimap.png")

from pymatting import cutout

cutout("input_image.png", "trimap.png", "cutout.png")