# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="qbmb46sKABc5"
# !pip3 install pixellib --upgrade

# + id="JFT-cXplE3fF"
# !wget https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.1/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5

# + id="DqKntJOw2hsG"
import pixellib
from pixellib.tune_bg import alter_bg
from matplotlib import pyplot as plt
import numpy as np
from PIL import Image
from IPython.display import Image as img
from pylab import rcParams

# + id="RkX6xITp4xav"
rcParams['figure.figsize'] = 10, 10

# + id="pLP_0UaHBEFI"
change_bg = alter_bg()

# + id="SA8lLOdNE5xd"
dir(change_bg)

# + id="uXcS5T3BBEIF"
change_bg.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")

# + id="ZsdNdqPcFcxe"
file_name = "image.jpg"
bg_file_name = "background_img.jpg"

# + [markdown] id="Ga5WlY2U6ygk"
# # Original Images

# + id="MZlrNJduF-Aq"
plt.imshow(Image.open(file_name))

# + id="8KmogvOz6v8T"
plt.imshow(Image.open(bg_file_name))

# + [markdown] id="Y8nGrcao63Yd"
# # Blur Background

# + id="fh9AojUeBL8s"
change_bg.blur_bg(file_name, 
                  moderate = True , 
                  output_image_name="blur_img.jpg")

# + id="AFNKj1GR2RVU"
plt.imshow(Image.open("blur_img.jpg"))

# + [markdown] id="5Eldf6vK67w7"
# # Gray Background

# + id="FyPNQ-zWBL_q"
change_bg.gray_bg(file_name, 
                  output_image_name="gray_img.jpg")

# + id="KnNe7lj35O8W"
plt.imshow(Image.open("gray_img.jpg"))

# + [markdown] id="PKye4pnw6_tC"
# # Background Colour Change

# + id="oYFdcRUfCor2"
change_bg.color_bg(file_name, 
                   colors = (123, 123, 123), 
                   output_image_name="colored_bg.jpg")

# + id="tjHCM4cFFFxc"
plt.imshow(Image.open("colored_bg.jpg"))

# + [markdown] id="D8PhGfde7Crd"
# # Background Change

# + id="amC623Ud5BS0"
change_bg.change_bg_img(f_image_path = file_name,
                        b_image_path = bg_file_name, 
                        output_image_name="new_img.jpg")

# + id="OHvoo6U2523c"
plt.imshow(Image.open("new_img.jpg"))

StarcoderdataJupyterScriptsDedupFiltered