Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions Tkinter/GUI_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import os
from tkinter import *
from tkinter import ttk, filedialog
import cv2
import requests
from PIL import Image, ImageTk
from background_image.backgorund_image import backgroundImage
root = Tk()
images = []
filter_type = ""

path_name = ""
def get_filter_type():

global filter_type, path_name
filter_type = type_choosen.get()
if filter_type == "color":
apply()
elif filter_type == "image":
filename = filedialog.askopenfilename(title="select File",
filetypes=(
("jpeg files", "*.jpg"), ("all files", "*.*"),
('png files', '*.png')))
backgroundImage(filter_type, images[-1], 0, filename)
render("../saved/temp.png")
else:
backgroundImage(filter_type, images[-1], 0, '../assest/background/back1.png')
render("../saved/temp.png")


def apply():
def apply_color():
b = {'Black':(0,0,0),'Green':(0,255,0),'White':(255,255,255),'Blue':(0,0,255),'Red':(255,0,0)}
backgroundImage("color", images[-1], b[color_choosen.get()], '../assest/background/back1.png')
render("../saved/temp.png")
colorButton = Button(text="Add color", padx=10, pady=10, fg="white", bg="#2596be", font=('arial', 15),
command=apply_color)
colorButton.grid(row=4, column=3)
m = StringVar()
color_choosen = ttk.Combobox(width=20, textvariable=m)
color_choosen['values'] = ('Black',
'Green',
'White',
'Blue',
'Red')

color_choosen.grid(column=2, row=4)
color_choosen.current(1)






def add_from_web():
img_url = entry.get()
entry.delete(0, END)
r = requests.get(img_url)
with open("../saved/web.png", 'wb') as f:
f.write(r.content)
images.append("../saved/web.png")
render(images[-1])



def render(image_withfilter):
img = Image.open(image_withfilter)
img = img.resize((500, 500))
img = ImageTk.PhotoImage(img)
img_label = Label(root, image=img)
img_label.photo = img
img_label.grid(row=0, column=0)

def browse():
filename = filedialog.askopenfilename(title="select File",
filetypes=(
("jpeg files", "*.jpg"), ("all files", "*.*"), ('png files', '*.png')))
images.append(filename)
render(images[-1])


def saving():
os.rename("../saved/temp.png", f"../saved/{entryy.get()}.png")
entryy.delete(0,END)


importButton = Button(text="Import", padx=10, pady=10, fg="white", bg="#2596be", font=('arial', 15), command=browse)
importButton.grid(row=0, column=3)

web_link_Button = Button(text="import web link", padx=10, pady=10, fg="white", bg="#2596be", font=('arial',15), command=add_from_web)
web_link_Button.grid(row=1, column=2)

typeButton = Button(text="Apply Filter", padx=10, pady=10, fg="white", bg="#2596be", font=('arial', 10), command=get_filter_type)
typeButton.grid(row=2, column=3)

saveButton = Button(text="Save", padx=10, pady=10, fg="white", bg="#2596be", font=('arial',15), command=saving)
saveButton.grid(row=3, column=2)

entry = Entry(width=20, bg="white")
entry.grid(row=1, column=1)
entryy = Entry(width=20, bg="white")
entryy.grid(row=3, column=1)

# label
ttk.Label(text="Select filter type :",
font=("Times New Roman", 10)).grid(column=1,
row=2, padx=10, pady=10)

n = StringVar()
type_choosen = ttk.Combobox(width=20, textvariable=n)

# Adding combobox drop down list
type_choosen['values'] = ('image',
'gray',
'blur',
'color',)

type_choosen.grid(column=2, row=2)
type_choosen.current(2)

root.mainloop()
Binary file removed background_image/Input_image/test.png
Binary file not shown.
Binary file removed background_image/Input_image/test4.png
Binary file not shown.
Binary file added background_image/Output_image/yahia2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions background_image/backgorund_image.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import pixellib
from check_directory import saveimage,check_image
from background_image.check_directory import saveimage, check_image
from pixellib.tune_bg import alter_bg
def backgroundImage(type,input_image,color,back_ground=''):
path_name =check_image()


def backgroundImage(type, input_image, color, back_ground):
path_name = "../saved/temp.png"
if path_name:
change_bg = alter_bg(model_type = "pb")
change_bg.load_pascalvoc_model("xception_pascalvoc.pb")
change_bg.load_pascalvoc_model("../background_image/xception_pascalvoc.pb")

if type == 'image':
change_bg.change_bg_img(f_image_path = input_image,b_image_path = back_ground, output_image_name=path_name)
change_bg.change_bg_img(f_image_path = input_image, b_image_path = back_ground, output_image_name=path_name)
if type == 'gray':
change_bg.gray_bg(input_image, output_image_name=path_name)
if type =='color':
change_bg.color_bg(input_image, colors=color, output_image_name=path_name)
if type == 'blur':
change_bg.blur_bg(input_image, low=True, output_image_name=path_name)
saveimage(path_name)


# saveimage(path_name)


# backgroundImage('gray','Output_image/test2.png','Input_image/lena.jpg')
8 changes: 4 additions & 4 deletions background_image/check_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import requests
def check_image():
path = input('enter the name of path output : ')
path_image = f'Output_image/{path}.png'
path_image = f'../saved/{path}.png'
file_exists = exists(path_image)
while file_exists:
path_name2 = input('this name is exist try another one or enter q : ')
if path_name2 == 'q':
path_image = False
break

path_image = f'Output_image/{path_name2}.png'
path_image = f'../saved/{path_name2}.png'
file_exists = exists(path_image)
return path_image

def saveimage(path):
print("close the window for image")
os.remove("../saved/web.png")
image = cv2.imread(path)
cv2.imshow('image window', image)
cv2.waitKey(0)
Expand All @@ -28,7 +28,7 @@ def saveimage(path):
return
def add_path(image_path,origin):

path_image = file_exist(origin)
path_image = "../saved/web.png"

if ':' in image_path and "\\" in image_path and 'http' not in image_path:
img = cv2.imread(image_path)
Expand Down
4 changes: 2 additions & 2 deletions background_image/filter_background_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def filter_background_image():
color = tuple(map(int, add_color.split(',')))

if type_filter == 1 :
backgroundImage(type_of_background,path_input_image,color,'../assest/background/back1.jpg')
backgroundImage(type_of_background,path_input_image,color,'../assest/background/back1.png')
if type_filter == 2 :
backgroundImage(type_of_background,path_input_image,background_filter,color,'../assest/background/back2.jpg')
backgroundImage(type_of_background,path_input_image,background_filter,color,'../assest/background/back2.png')

filter_background_image()