diff --git a/Tkinter/GUI_background.py b/Tkinter/GUI_background.py new file mode 100644 index 0000000..ef6c4c7 --- /dev/null +++ b/Tkinter/GUI_background.py @@ -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() \ No newline at end of file diff --git a/background_image/Input_image/test.png b/background_image/Input_image/test.png deleted file mode 100644 index 1202ab7..0000000 Binary files a/background_image/Input_image/test.png and /dev/null differ diff --git a/background_image/Input_image/test4.png b/background_image/Input_image/test4.png deleted file mode 100644 index 1202ab7..0000000 Binary files a/background_image/Input_image/test4.png and /dev/null differ diff --git a/background_image/Output_image/yahia2.png b/background_image/Output_image/yahia2.png new file mode 100644 index 0000000..f465ae0 Binary files /dev/null and b/background_image/Output_image/yahia2.png differ diff --git a/background_image/backgorund_image.py b/background_image/backgorund_image.py index b6b2705..343d0c3 100644 --- a/background_image/backgorund_image.py +++ b/background_image/backgorund_image.py @@ -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') diff --git a/background_image/check_directory.py b/background_image/check_directory.py index 1e2dcd0..c8c6a1f 100644 --- a/background_image/check_directory.py +++ b/background_image/check_directory.py @@ -4,7 +4,7 @@ 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 : ') @@ -12,12 +12,12 @@ def check_image(): 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) @@ -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) diff --git a/background_image/filter_background_image.py b/background_image/filter_background_image.py index 3d2fa87..6072edb 100644 --- a/background_image/filter_background_image.py +++ b/background_image/filter_background_image.py @@ -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() \ No newline at end of file