import sys import customtkinter from tkinter import filedialog import ffmpeg from datetime import datetime import numpy as np import cv2 import glob import shutil import albumentations as A import random import os import imgaug.augmenters as iaa import threading import time from PIL import Image np.complex = np.complex128 np.bool = np.bool_ class App(customtkinter.CTk): def __init__(self): super().__init__() #to store build number using txt file self.build_file = 'build_number.txt' self.program_name = str(__file__) #taking version info from python files name self.version = self.program_name.split("\\")[-1][:-3] #accesing build number inside python file name to change it self.build_number = int(self.version.split(".")[2]) #taking build number dynamicly self.build_number_main() build_number = self.get_build_number(self.build_file) #taking current date time for version now = datetime.now() formatted_now = now.strftime('%Y%m%d.%H%M00') #create copy of this code with new version infos current_file_name = f"{self.program_name.split("\\")[-1]}" new_file_name = f"0.10.{build_number}.{formatted_now}.py" shutil.copy(current_file_name, new_file_name) #creating main windows title and resolution self.title("Augmentation") self.geometry("1000x800") self.iconbitmap("icon3.ico") # self.resizable(False,False) #to change row value creating a variable self.row = 4 self.grid_rowconfigure(0, weight=1) self.grid_columnconfigure((1,2), weight=1) #logo image in navigation menu self.logo_image = customtkinter.CTkImage(Image.open("icon3.ico"), size=(100, 100)) #creating navigation frame self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0, width=220) self.navigation_frame.grid(row=0, column=0, sticky="nsew") self.navigation_frame.grid_rowconfigure(6, weight=1) #adding logo image to navigation menu self.navigation_frame_label = customtkinter.CTkLabel(self.navigation_frame, text="", image=self.logo_image, compound="left", font=customtkinter.CTkFont(family="Frekuent-Mono", size=15, weight="bold")) self.navigation_frame_label.grid(row=0, column=0, padx=60, pady=20) #adding image to video button to navigation menu self.itv_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, width=50, border_spacing=10, text="Image to Video", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.itv_button_event) self.itv_button.grid(row=1, column=0, sticky="ew", columnspan = 2) #adding image augmentation button to navigation menu self.ia_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, width=50, border_spacing=10, text="Image Augmentation", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.ia_button_event) self.ia_button.grid(row=2, column=0, sticky="ew", columnspan=2) #adding video augmentation button to navigation menu self.va_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, width=50, border_spacing=10, text="Video Augmentation", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.va_button_event) self.va_button.grid(row=self.row, column=0, sticky="ew", columnspan = 2) #frame for image augmentation main titles self.imageSecondRowFrame_nav = customtkinter.CTkFrame(self.navigation_frame) self.imageSecondRowFrame_nav.grid(row=3, column=0) self.imageSecondRowFrame_nav.configure(fg_color="transparent") #fram for image augmentation main titles self.videoSecondRowFrame_nav = customtkinter.CTkFrame(self.navigation_frame) self.videoSecondRowFrame_nav.grid(row=5, column=0) self.videoSecondRowFrame_nav.configure(fg_color="transparent") #creating appearance menu for color mode self.appearance_mode_menu = customtkinter.CTkOptionMenu(self.navigation_frame, values=["Light", "Dark", "System"], command=self.change_appearance_mode_event) #default value for appearance menu self.appearance_mode_menu.set("Dark") self.appearance_mode_menu.grid(row=6, column=0, padx=20, pady=20, sticky="s") #creating option menu for scaling size self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.navigation_frame, values=["80%", "90%", "100%", "110%", "120%"], command=self.change_scaling_event) #default value for scaling option menu self.scaling_optionemenu.set("%100") self.scaling_optionemenu.grid(row=7, column=0, padx=20, pady=(10, 20)) #creating image to video frame self.itv_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.itv_frame.grid_columnconfigure(0, weight=1) self.itv_frame.grid_rowconfigure((0,1,2), weight=1) # creating augmentation to video frame self.atv_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.atv_frame.grid_columnconfigure(0, weight=1) self.atv_frame.grid_rowconfigure((0, 1, 2), weight=1) #printing version info to navigation bar self.versionLabel = customtkinter.CTkLabel(self.navigation_frame, text=f"Version: {self.version}", text_color="gray") self.versionLabel.grid(row=8, column=0, padx=20, pady=(10, 20)) #creating image augmentation frame self.ia_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.ia_frame.grid_columnconfigure((0, 1), weight=1) self.ia_frame.grid_rowconfigure((0, 1, 2, 3), weight=1) #creating image augmentation settings frame self.ia02_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.ia02_frame.grid_rowconfigure((0, 1), weight=1) self.ia02_frame.grid_columnconfigure(0, weight=1) #creating video augmentation frame self.va_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.va_frame.grid_columnconfigure((0, 1), weight=1) self.va_frame.grid_rowconfigure((0, 1, 2, 3), weight=1) #creating video augmentation settings frame self.va02_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.va02_frame.grid_rowconfigure((0, 1), weight=1) self.va02_frame.grid_columnconfigure(0, weight=1) #selecting openning frame self.select_frame_by_name("itv") self.itv_button_event() #to get build number dynamically from txt def get_build_number(self, file_path): try: with open(file_path, 'r') as file: build_number = int(file.read().strip()) except FileNotFoundError: build_number = self.build_number except ValueError: build_number = self.build_number return build_number #change the build number inside text file every time def set_build_number(self, file_path, build_number): with open(file_path, 'w') as file: file.write(str(build_number)) #using build number functions def build_number_main(self): self.build_file = 'build_number.txt' current_build_number = self.get_build_number(self.build_file) new_build_number = current_build_number + 1 self.set_build_number(self.build_file, new_build_number) #updating font size of image to video def update_font_imagetoVideo(self, event): width = self.winfo_width() font_size = max(10, (width // 300) + 13) tittle_font_size = max(10, (width // 300) + 15) self.videotitle.configure(font=("Frekuent-Mono", tittle_font_size)) self.frameLabel.configure(font=("Frekuent-Mono", font_size)) self.imageNumLabel.configure(font= ("Frekuent-Mono", font_size)) self.fakeFrameNumLabel.configure(font= ("Frekuent-Mono", font_size)) self.startButton.configure(font= ("Frekuent-Mono", font_size)) ################################################################## self.foldertitle.configure(font= ("Frekuent-Mono", tittle_font_size)) self.imageFolderLabel.configure(font= ("Frekuent-Mono", font_size)) self.imageFolderEntry.configure(font= ("Frekuent-Mono", font_size)) self.videoFolderLabel.configure(font= ("Frekuent-Mono", font_size)) self.videoFolderEntry.configure(font= ("Frekuent-Mono", font_size)) #updating font size of image to video progress bar def update_font_video_progress(self, event): width = self.winfo_width() font_size = max(10, (width // 300) + 13) self.progresstitle.configure(font=("Frekuent-Mono", font_size)) self.createVideoLabel.configure(font=("Frekuent-Mono", font_size)) #updating font size of image augmentation def update_font_image_augmentation(self, event): width = self.winfo_width() font_size = max(10, (width // 300) + 13) tittle_font_size = max(10, (width // 300) + 15) self.foldertitle.configure(font= ("Frekuent-Mono", tittle_font_size)) self.imageFolderLabel.configure(font= ("Frekuent-Mono", font_size)) self.videoFolderLabel.configure(font= ("Frekuent-Mono", font_size)) self.imageFolderEntry.configure(font= ("Frekuent-Mono", font_size)) self.videoFolderEntry.configure(font= ("Frekuent-Mono", font_size)) self.augmentationSettings.configure(font= ("Frekuent-Mono", font_size)) for key in self.switch.keys(): self.switch[key].configure(font= ("Frekuent-Mono", font_size)) for key in self.frame.keys(): self.frame[key].configure(label_font= ("Frekuent-Mono", tittle_font_size)) #updating font size of image augmentation settings def update_font_image2_augmentation(self, event): width = self.winfo_width() font_size = max(10, (width // 300) + 13) tittle_font_size = max(10, (width // 300) + 15) for key in self.titleLabel.keys(): self.titleLabel[key].configure(font= ("Frekuent-Mono", tittle_font_size)) for key in self.augmentationLabel.keys(): self.augmentationLabel[key].configure(font= ("Frekuent-Mono", font_size)) #update ready buttons font size def update_font_ready_button(self, event): width = self.winfo_width() font_size = max(10, (width // 300) + 13) self.startButton2.configure(font=("Frekuent-Mono", font_size)) self.colorLabel.configure(font=("Frekuent-Mono", font_size)) #to change main frame def select_frame_by_name(self, name): #changing color of selected button self.itv_button.configure(fg_color=("gray75", "gray25") if name == "itv" else "transparent") self.ia_button.configure(fg_color=("gray75", "gray25") if name == "ia" else "transparent") self.ia_button.configure(fg_color=("gray75", "gray25") if name == "ia02" else "transparent") self.va_button.configure(fg_color=("gray75", "gray25") if name == "va" else "transparent") self.va_button.configure(fg_color=("gray75", "gray25") if name == "va02" else "transparent") if name == "itv": self.itv_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.itv_frame.grid_forget() if name == "atv": self.atv_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.atv_frame.grid_forget() if name == "ia": self.ia_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.ia_frame.grid_forget() if name == "ia02": self.ia02_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.ia02_frame.grid_forget() if name == "va": self.va_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.va_frame.grid_forget() if name == "va02": self.va02_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.va02_frame.grid_forget() #event of image to video button on navigation bar def itv_button_event(self): self.select_frame_by_name("itv") self.imagetoVideo() self.imageSecondRowFrame_nav.grid_forget() self.videoSecondRowFrame_nav.grid_forget() #event of image augmentation button on navigation bar def ia_button_event(self): self.row = 4 self.image_augmentation() self.imageSecondRowFrame_nav.grid(row=3, column=0) self.videoSecondRowFrame_nav.grid_forget() self.select_frame_by_name("ia") #event of video augmentation button on navigation bar def va_button_event(self): self.row = 3 self.video_augmentation() self.select_frame_by_name("va") self.videoSecondRowFrame_nav.grid(row=5, column=0) self.imageSecondRowFrame_nav.grid_forget() #event of image augmentation ready button on navigation bar def ia_ready_button_event(self): self.image_augmentation_02() self.select_frame_by_name("ia02") self.imageSecondRowFrame_nav.grid_forget() self.videoSecondRowFrame_nav.grid_forget() #event of video augmentation ready button on navigation bar def va_ready_button_event(self): self.video_augmentation_02() self.select_frame_by_name("va02") self.imageSecondRowFrame_nav.grid_forget() self.videoSecondRowFrame_nav.grid_forget() #change scaling on navigation bar def change_scaling_event(self, new_scaling: str): new_scaling_float = int(new_scaling.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) #change mode on navigation bar def change_appearance_mode_event(self, new_appearance_mode): customtkinter.set_appearance_mode(new_appearance_mode) #to create video from images that you select def imagetoVideo(self): #change font size of image to video self.bind("", self.update_font_imagetoVideo) #set default values for folders self.video_input_folder = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\images3") self.video_output_folder = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\video") #set fonts for deafult fonts self.custom_font = ("Frekuent-Mono", 15) self.custom_font2 = ("Frekuent-Mono", 14) #creating browse button from image self.browseImageSizeWidth = 23 self.browseImageSizeHeight = 23 self.title_image = customtkinter.CTkImage( light_image=Image.open("fileiconbt.png"), dark_image=Image.open("fileiconbt.png"), size=(self.browseImageSizeWidth, self.browseImageSizeHeight)) #first row of image to video self.firstRowFrame = customtkinter.CTkFrame(self.itv_frame) self.firstRowFrame.grid(row=0, column=0, pady=(10, 10), padx=30, sticky="nwes") self.firstRowFrame.grid_rowconfigure((0, 1, 2), weight=1) self.firstRowFrame.grid_columnconfigure(1, weight=1) #first rows title self.foldertitle = customtkinter.CTkLabel(self.firstRowFrame, text="Folder Settings:", font=self.custom_font2) self.foldertitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") #to set image folder self.imageFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Image Folder:", font=self.custom_font2) self.imageFolderLabel.grid(row=1, column=0, padx=(15, 15), pady=(15, 10), sticky="w") self.imageFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Image Folder:", textvariable=self.video_input_folder, height=50, corner_radius=0) self.imageFolderEntry.grid(row=1, column=1, pady=(20, 10), sticky="ew", columnspan=1) self.imageFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, command=self.browse_video_folder, text="", height=50, width=60 , corner_radius=0) self.imageFolderBrowse.grid(row=1, column=2, pady=(20, 10), padx=(0, 20), columnspan=1) #to set video folder self.videoFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Video Saving Folder:", font=self.custom_font2) self.videoFolderLabel.grid(row=2, column=0, padx=(15, 15), pady=(20, 30), sticky="w") self.videoFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Video Saving Folder:", textvariable=self.video_output_folder, height=50, corner_radius=0) self.videoFolderEntry.grid(row=2, column=1, pady=(20, 30), sticky="ew", columnspan=1) self.videoFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, command=self.browse_video_output_folder, text="", height=50, width=60 , corner_radius=0) self.videoFolderBrowse.grid(row=2, column=2, pady=(20, 30), padx=(0, 20), columnspan=1) #second row of image to video self.secondRowFrame = customtkinter.CTkFrame(self.itv_frame) self.secondRowFrame.grid(row=1, column=0, pady=(0, 10), padx=30, sticky="nwes", columnspan=2) self.secondRowFrame.grid_rowconfigure((0, 2, 3, 4, 8), weight=1) self.secondRowFrame.grid_columnconfigure((1, 2), weight=1) #title of video settings self.videotitle = customtkinter.CTkLabel(self.secondRowFrame, text="Video Settings:", font=self.custom_font2) self.videotitle.grid(row=0, column=0, sticky="w", padx=10, pady=(5,0)) #creating fps variable and slider to set self.frameRateVar = customtkinter.IntVar(value=15) self.frameRate = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_frame_label(value), height=50, button_corner_radius=4, corner_radius=0) self.frameRate.grid(row=2, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.frameRate.set(self.frameRateVar.get()) self.frameLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Frame Rate: {self.frameRateVar.get()}", font=self.custom_font2) self.frameLabel.grid(row=2, column=0, sticky="w", padx=(15, 0)) #creating image num variable and slider to set self.imageNumVar = customtkinter.IntVar(value=3) self.imageNum = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_image_label(value), height=50, button_corner_radius=4, corner_radius=0) self.imageNum.grid(row=3, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.imageNum.set(self.imageNumVar.get()) self.imageNumLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Image Second: {self.imageNumVar.get()}", font=self.custom_font2) self.imageNumLabel.grid(row=3, column=0, sticky="w", padx=(15, 0)) #creating fake frame num variable and slider to set self.fakeFrameNumVar = customtkinter.IntVar(value=3) self.fakeFrameNum = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_fakeframe_label(value), height=50, button_corner_radius=4, corner_radius=0) self.fakeFrameNum.grid(row=4, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.fakeFrameNum.set(self.fakeFrameNumVar.get()) self.fakeFrameNumLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Fake Frame Second: {self.fakeFrameNumVar.get()}", font=self.custom_font2) self.fakeFrameNumLabel.grid(row=4, column=0, sticky="w", padx=(15, 0)) #create start button to start image to video proogress self.startButton = customtkinter.CTkButton(self.secondRowFrame, text="Start", command=self.startImagetoVideoProgress, font=self.custom_font2, height=30, width=150) self.startButton.grid(row=8, column=0, columnspan=3, padx=200, pady=10) #start video progress def startImagetoVideoProgress(self): thread = threading.Thread(target=self.imagetoVideoProgress) thread.start() #creating progress bar of image to video def imagetoVideoProgress(self): #update font size of image to video progress bars self.bind("", self.update_font_imagetoVideo) #creating third row of image to video self.thirdRowFrame = customtkinter.CTkFrame(self.itv_frame) self.thirdRowFrame.grid(row=2, column=0, pady=(0, 10), padx=30, sticky="nwes") self.thirdRowFrame.grid_rowconfigure((0, 1, 2), weight=1) self.thirdRowFrame.grid_columnconfigure(1, weight=1) #to calculate step size of progress bar image_folder = os.path.abspath(self.video_input_folder.get()) images = [img for img in os.listdir(image_folder) if img.lower().endswith('.jpg')] self.determinate = 100 / len(images) #progress bar title self.progresstitle = customtkinter.CTkLabel(self.thirdRowFrame, text="Progress Bars:", font=self.custom_font2) self.progresstitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") self.createVideoLabel = customtkinter.CTkLabel(self.thirdRowFrame, text="Video Creating Progress:", font=self.custom_font) self.createVideoLabel.grid(row=1, column=0, padx=(15, 5), pady=20, sticky="w") self.createVideoBar = customtkinter.CTkProgressBar(self.thirdRowFrame, orientation="horizontal", height=50, corner_radius=0, determinate_speed=self.determinate/2) self.createVideoBar.grid(row=1, column=1, sticky="we", pady=20, padx=(20,30)) self.createVideoBar.set(0) self.augmentation_values = [] #if output folder not exist create one if not os.path.exists(self.video_output_folder.get()): print(f"Creating output folder: {self.video_output_folder.get()}") os.makedirs(self.video_output_folder.get()) #base names of files base_filename_mp4 = 'output.mp4' base_filename_h265 = 'output_h265.mp4' output_mp4 = os.path.join(self.video_output_folder.get(), base_filename_mp4) output_h265_mp4 = os.path.join(self.video_output_folder.get(), base_filename_h265) #if name exist create different one index = 0 while os.path.exists(output_mp4): index += 1 base_filename_mp4 = f'output_{index}.mp4' output_mp4 = os.path.join(self.video_output_folder.get(), base_filename_mp4) #if name exist create different one index = 0 while os.path.exists(output_h265_mp4): index += 1 base_filename_h265 = f'output_h265_{index}.mp4' output_h265_mp4 = os.path.join(self.video_output_folder.get(), base_filename_h265) #calculate second of image and fakeframe imagesecond = self.frameRateVar.get() * self.imageNumVar.get() fakeframesecond = self.frameRateVar.get() * self.fakeFrameNumVar.get() image_folder = os.path.abspath(self.video_input_folder.get()) images = [img for img in os.listdir(image_folder) if img.lower().endswith('.jpg')] if not images: print(f"No JPEG images found in {self.video_input_folder.get()}. Exiting.") return frame = cv2.imread(os.path.join(image_folder, images[0])) if frame is None: print(f"Failed to load image: {images[0]}") return height, width, layers = frame.shape out = cv2.VideoWriter(output_mp4, cv2.VideoWriter_fourcc(*'mp4v'), self.frameRateVar.get(), (width, height)) black_frame = np.zeros((height, width, 3), dtype=np.uint8) for image in images: img_path = os.path.join(image_folder, image) img = cv2.imread(img_path) if img is None: print(f"Failed to load image: {img_path}. Skipping.") continue for _ in range(imagesecond): out.write(img) for _ in range(fakeframesecond): out.write(black_frame) self.createVideoBar.step() time.sleep(0.1) out.release() self.h265() def h265(self): base_filename_mp4 = 'output.mp4' base_filename_h265 = 'output_h265.mp4' output_h265_mp4 = os.path.join(self.video_output_folder.get(), base_filename_h265) index = 0 while os.path.exists(output_h265_mp4): index += 1 base_filename_h265 = f'output_h265_{index}.mp4' output_h265_mp4 = os.path.join(self.video_output_folder.get(), base_filename_h265) base_filename_mp4 = f'output_{index}.mp4' output_mp4 = os.path.join(self.video_output_folder.get(), base_filename_mp4) if os.path.exists(output_mp4): self.convert_to_h265(output_mp4, output_h265_mp4) else: print(f"Failed to create MP4 video at {output_mp4}") def convert_to_h265(self, input_video, output_video): try: stream = ffmpeg.input(input_video) stream = ffmpeg.output(stream, output_video, vcodec='libx265') ffmpeg.run(stream, capture_stdout=True, capture_stderr=True) print(f"Video converted to H.265: {output_video}") except ffmpeg.Error as e: print(f"Error converting video: {e.stderr.decode()}") def browse_video_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.video_input_folder.set(folder_path) def browse_video_output_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.video_output_folder.set(folder_path) def update_frame_label(self, value): self.frameRateVar.set(value) self.frameLabel.configure(text=f"Frame Rate: {self.frameRateVar.get()}") def update_image_label(self, value): self.imageNumVar.set(value) self.imageNumLabel.configure(text=f"Image second: {self.imageNumVar.get()}") def update_fakeframe_label(self, value): self.fakeFrameNumVar.set(value) self.fakeFrameNumLabel.configure(text=f"Fake Frame second: {self.fakeFrameNumVar.get()}") def image_augmentation(self): self.images_filepath = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\images3") self.imagesAugmented_filepath = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\Augmented") self.frame = {} self.label = {} self.var = {} self.switch = {} self.switch2 = {} self.switchLabel = {} self.imageAugmentations = [["Weather", "Fog02", "Rainy01", "Snowy02", "Cloudy", "Snowy", "Fog01", "Rainy02_Brightness_Drop width_Blur_1", "Frost"], ["Crop", "Crop and Fill", "Rotate_Rotate_1", "Shear_ShearRate_1", "ReflectX", "ReflectY", "ShearX_Shear rate for x_1", "ShearY_Shear rate for y_1"], ["Color", " Changed Color Space", "Brightness_Brightness_1", "Hue and Saturation_Saturation_1", "Hue and Saturation 2_Saturation_1", "Color Space", "Gray-Scale_Alpha_1", "Color Temperature", "Gamma Contrast", "Sigmoid Contrast", "Log Contrast", "All Clahe", "Multiply", "Dropout2D", "Original"] ] self.firstRowFrame = customtkinter.CTkFrame(self.ia_frame) self.firstRowFrame.grid(row=0, column=0, sticky="nswe", padx=10 , pady=(10,10), columnspan = 2) # self.firstRowFrame.configure(fg_color="transparent") self.firstRowFrame.grid_columnconfigure(1, weight=1) self.firstRowFrame.grid_rowconfigure((0,1,2), weight=1) self.foldertitle = customtkinter.CTkLabel(self.firstRowFrame, text="Folder Settings:", font=self.custom_font2) self.foldertitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") self.imageFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Original Images Folder:", font=self.custom_font) self.imageFolderLabel.grid(row=1, column=0, padx=(50, 10), pady=(15, 10), sticky="w") self.imageFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Original Images Folder:", textvariable=self.images_filepath, height=50, corner_radius=0) self.imageFolderEntry.grid(row=1, column=1, pady=(15, 10), sticky="we", columnspan=1) self.imageFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, width=60, height=50, command=self.browse_images_folder, text="", corner_radius=0) self.imageFolderBrowse.grid(row=1, column=2, pady=(15, 10), padx=5, columnspan=1, sticky="w") self.videoFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Augmented Images Folder:", font=self.custom_font) self.videoFolderLabel.grid(row=2, column=0, padx=(50, 10), pady=(10, 30), sticky="w") self.videoFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Augmented Images Folder:", textvariable=self.imagesAugmented_filepath, height=50, corner_radius=0) self.videoFolderEntry.grid(row=2, column=1, pady=(10, 30), sticky="we", columnspan=1) self.videoFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, width=60, height=50, command=self.browse_augmented_folder, text="", corner_radius=0) self.videoFolderBrowse.grid(row=2, column=2, pady=(10, 30), padx=5, columnspan=1, sticky="w") self.imageAugmentation_values = self.switches(self.imageAugmentations, self.ia_frame, self.ia_ready_button_event, self.imageSecondRowFrame_nav) def switches(self, augmentations, frame, event, navFrame): self.frame_count = 0 column_count = 0 row_count = 0 self.secondRowFrame = customtkinter.CTkFrame(frame) self.secondRowFrame.grid(row=1, column=0, sticky="nswe", padx=10, pady=(10,10), columnspan = 2) # self.secondRowFrame.configure(fg_color="transparent") self.secondRowFrame.grid_columnconfigure((0,1), weight=1) self.secondRowFrame.grid_rowconfigure((0,1), weight=1) self.augmentation_values = [] for augmentation in augmentations: titleCount = len(augmentations) augmentation_name = f"{augmentation[0]}" self.frame[augmentation_name] = customtkinter.CTkScrollableFrame(self.secondRowFrame, width=300, height=200, label_text=f"{str(augmentation[0]).split("_")[0]} Augmentation", corner_radius=0) if column_count >= titleCount/2: row_count += 1 column_count = 0 if column_count > 3: row_count += 1 column_count = 0 self.frame[augmentation_name].grid(row=row_count, column=column_count, padx=5, pady=(10, 0), sticky="nswe") self.frame[augmentation_name].grid_columnconfigure(0, weight=1) self.var[augmentation_name] = customtkinter.StringVar(value=".") self.augmentation_values.append(self.var[augmentation_name]) self.switch2[augmentation_name] = customtkinter.CTkSwitch( navFrame, text=f"{str(augmentation[0]).split("_")[0]} Augmentation", variable=self.var[augmentation_name], onvalue=2, offvalue=3, command=lambda name=augmentation_name: self.update_second_row_switches(name) ) self.switch2[augmentation_name].select() self.switch2[augmentation_name].grid(row=self.frame_count, column=0, padx=(40,0), pady=(10, 0), sticky="w") column_count += 1 self.frame_count += 1 for augmentationType in augmentation[1:]: self.type_name = f"{augmentation[0]}{augmentationType}" self.image_type = f"{augmentationType}" self.var[self.type_name] = customtkinter.StringVar(value=f".") self.switch[self.type_name] = customtkinter.CTkSwitch( self.frame[augmentation_name], text=f"{str(augmentationType).split("_")[0]} Augmentation", variable=self.var[self.type_name], onvalue=1, offvalue=0 ) self.question_mark_image = customtkinter.CTkImage(Image.open("info.png")) self.switch[self.type_name].select() self.switch[self.type_name].grid(row=self.frame_count, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew") self.augmentation_values.append(self.var[self.type_name]) self.switchLabel[self.type_name] = customtkinter.CTkLabel(self.frame[augmentation_name], text="", image=self.question_mark_image) self.switchLabel[self.type_name].grid(row=self.frame_count, column=1, pady=(10, 10), sticky="w") self.switchLabel[self.type_name].bind("", lambda event, name=self.type_name, imageName=self.image_type: self.show_popup(name, imageName)) self.switchLabel[self.type_name].bind("", self.hide_popup) self.popup_window = None self.frame_count += 1 self.bind("", self.update_font_image_augmentation) self.thirdRowFrame = customtkinter.CTkFrame(frame) self.thirdRowFrame.grid(row=2, column=0, sticky="nswe", columnspan = 2, padx=10) self.thirdRowFrame.grid_rowconfigure(0, weight=1) self.thirdRowFrame.grid_columnconfigure(0, weight=1) self.thirdRowFrame.configure(fg_color="transparent") self.augmentationSettings = customtkinter.CTkButton(self.thirdRowFrame, text="Ready", anchor="center", command=event ,width=200, height=30) self.augmentationSettings.grid( row=0, column=0, sticky="we", columnspan=2, padx=0) return self.augmentation_values def show_popup(self, typename, imageName): if not self.popup_window: self.create_popup_window(imageName) if self.popup_window: x = self.switchLabel[typename].winfo_rootx() + self.switchLabel[typename].winfo_width() y = self.switchLabel[typename].winfo_rooty() + self.switchLabel[typename].winfo_height() self.popup_window.geometry(f"+{x}+{y}") self.popup_window.deiconify() def create_popup_window(self, imageName): self.popup_window = customtkinter.CTkToplevel(self.switchLabel[self.type_name]) self.popup_window.overrideredirect(True) self.popup_window.configure(background='white') self.popup_window.grid_rowconfigure(0, weight=1) self.popup_window.grid_columnconfigure(0, weight=1) image = Image.open("icon3.ico") width, height = image.size answer_image = customtkinter.CTkImage(Image.open("icon3.ico")) answer_label = customtkinter.CTkLabel(self.popup_window, image=answer_image, text="") answer_label.grid(row=0, column=0, sticky="nswe") def hide_popup(self, event=None): if self.popup_window: self.popup_window.withdraw() def update_second_row_switches(self, augmentation_name): first_row_switch_state = self.var[augmentation_name].get() for switch_name in self.switch: if switch_name.startswith(augmentation_name) and switch_name != augmentation_name: if first_row_switch_state == "2": self.switch[switch_name].select() else: self.switch[switch_name].deselect() def browse_images_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.images_filepath.set(folder_path) def browse_augmented_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.imagesAugmented_filepath.set(folder_path) def image_augmentation_02(self): self.frame = {} self.augmentationVar = {} self.augmentationLabel = {} self.insideFrame = {} self.augmentationNames = [] self.titleLabel = {} self.imagesFilePath = self.images_filepath.get() self.augmentedFilePath = self.imagesAugmented_filepath.get() #all augmentations true or false values if title is true = 2 false = 3 if subtitle is true = 1 false = 0 self.augmentationTrueFalse = [var.get() for var in self.imageAugmentation_values] self.firstRow = customtkinter.CTkFrame(self.ia02_frame) self.firstRow.grid(row=0, column=0, sticky="nswe", padx=10, pady=10, columnspan=1) self.firstRow.grid_rowconfigure((0, 1), weight=1) self.firstRow.grid_columnconfigure((0, 1), weight=1) #all augmentation styles in one list self.augmentationsAllinOne = [] self.rowCount = 0 self.columnCount = 0 self.trackNumList = [] self.uniqueTrackNumList = [] self.styleNames =[] self.uniqueStyleNames = [] self.trackNumbers = [] self.frameNames = [] self.uniqueFrameNames = [] self.frameCount = 0 self.insideRowCount = 0 for x in range(len(self.imageAugmentations)): for y in range(len(self.imageAugmentations[x])): self.augmentationsAllinOne.append(self.imageAugmentations[x][y]) for i in range(len(self.augmentationTrueFalse)): if str(self.augmentationTrueFalse[i]) == str(self.augmentationsAllinOne[i]).split("_")[-1]: #to track augmentation title location self.trackNumber = i self.trackNumbers.append(i) while self.augmentationTrueFalse[self.trackNumber] == "1" or self.augmentationTrueFalse[self.trackNumber] == "0": # decrease i for find the augmentation title self.trackNumber -= 1 self.trackNumList.append(self.trackNumber) self.uniqueTrackNumList = set(self.trackNumList) for i in self.uniqueTrackNumList: self.frame_name = f"{self.augmentationsAllinOne[i]}" #creating scroable frame for each Augmentation Title self.frame[self.frame_name] = customtkinter.CTkScrollableFrame(self.firstRow, width=320, height=250, label_text=f"{self.augmentationsAllinOne[i]} Settings:", label_font=self.custom_font) self.frame[self.frame_name].grid(row=self.rowCount, column=self.columnCount, sticky="nswe", padx=(10, 10), pady=15, columnspan=1) self.frame[self.frame_name].grid_columnconfigure(0, weight=1) self.columnCount += 1 if self.columnCount > len(self.uniqueTrackNumList) / 2: self.rowCount += 1 self.columnCount = 0 self.frameNames.append(self.frame_name) self.uniqueFrameNames = set(self.frameNames) for j in self.trackNumbers: index_to_sublist = [] current_index = 0 for sublist in self.imageAugmentations: index_to_sublist.extend([current_index] * len(sublist)) current_index += 1 results = self.imageAugmentations[index_to_sublist[j]][0] if str(self.augmentationTrueFalse[j]) == str(self.augmentationsAllinOne[j]).split("_")[-1]: rowCount = len(str(self.augmentationsAllinOne[j]).split("_")[1:-1]) self.style = str(self.augmentationsAllinOne[j]).split("_")[0] self.insideRowCount = 0 self.frameCount += 1 self.insideFrame[self.style] = customtkinter.CTkFrame(self.frame[results], border_width=3) self.insideFrame[self.style].grid(row=self.frameCount, column=0, sticky="we", pady=15) self.insideFrame[self.style].grid_columnconfigure(1, weight=1) self.titleLabel[self.style] = customtkinter.CTkLabel(self.insideFrame[self.style], text=f"{self.style} Settings:", font=self.custom_font, anchor="w") self.titleLabel[self.style].grid(row=self.insideRowCount, column=0 , columnspan=2, sticky="we", pady=(5, 20), padx=5) self.insideRowCount += 1 for row in range(rowCount): temp1 = str(self.augmentationsAllinOne[j]).split("_")[1:-1][row] self.temp = self.create_unique_variable_name(temp1, self.augmentationVar) self.augmentationVar[self.temp] = customtkinter.IntVar(value=1) self.augmentationSlider = customtkinter.CTkSlider(self.insideFrame[self.style], from_=0, to=100, width=150, command=lambda value, a=self.temp, temp=temp1, style=self.style: self.update_augmentation_label(value, a, temp, style)) self.augmentationSlider.grid(row=row + 1, column=1, pady=15, sticky="we", padx=10) self.augmentationSlider.set(self.augmentationVar[self.temp].get()) self.augmentationLabel[self.temp] = customtkinter.CTkLabel(self.insideFrame[self.style], text=f"{temp1}: {self.augmentationVar[self.temp].get()}", font=self.custom_font) self.augmentationLabel[self.temp].grid(row=row + 1, column=0, sticky="w", pady=15, padx=(20, 40)) self.bind("", self.update_font_image2_augmentation) self.secondRow = customtkinter.CTkFrame(self.ia02_frame) self.secondRow.grid(row=1, column=0, sticky="nswe", padx=10, pady=5, columnspan=1) self.secondRow.columnconfigure((2), weight=1) self.secondRow.rowconfigure(0, weight=1) # self.secondRow.configure(fg_color="transparent") self.startButton2 = customtkinter.CTkButton(self.secondRow, text="Ready", anchor="center", width=200, height=30, command=lambda: self.imageReady_button()) self.startButton2.grid(row=0, column=1, columnspan=2, sticky="we") def imageReady_button(self): self.startButton2.grid_forget() self.bind("", self.update_font_ready_button) rowCount = 0 self.custom_font = ("Frekuent-Mono", 15) self.colorLabel = customtkinter.CTkLabel(self.secondRow, text=f"Augmentations: ", font=self.custom_font) self.colorLabel.grid(row=0, column=1, sticky="nsw", pady=15, padx=(15, 0)) rowCount += 1 self.progressBar = customtkinter.CTkProgressBar(self.secondRow, orientation="horizontal", height=20, progress_color="green", corner_radius=0) self.progressBar.grid(row=0, column=2, pady=15, columnspan=2, sticky="nswe", padx=10) self.progressBar.set(0) self.secondRow.update_idletasks() rowCount += 1 self.imageMain() def on_no(self): # Close the current popup self.video_popup.destroy() # Create a new window with the message new_window = customtkinter.CTkToplevel(self.ia02_frame) new_window.title("Image Locations") new_window.geometry("400x200") label = customtkinter.CTkLabel(new_window, text=f"Augmented image location is \n {self.imagesAugmented_filepath.get()}") label.pack(pady=20) close_button = customtkinter.CTkButton(new_window, text="Close", command=sys.exit) close_button.pack(pady=20) def on_yes(self): # Close the current popup self.video_popup.destroy() self.select_frame_by_name("atv") self.augmentedtoVideo() def show_video_popup(self): self.video_popup = customtkinter.CTkToplevel(self.ia02_frame) self.video_popup.overrideredirect(True) self.video_popup.configure(background='white') self.video_popup.grid_rowconfigure(0, weight=1) self.video_popup.grid_columnconfigure(0, weight=1) # Center the popup self.video_popup.update_idletasks() popup_width = 400 popup_height = 200 self.video_popup.geometry(f'{popup_width}x{popup_height}') self.video_popup.update_idletasks() x = self.winfo_x() + (self.winfo_width() // 2) - (self.video_popup.winfo_width() // 2) y = self.winfo_y() + (self.winfo_height() // 2) - (self.video_popup.winfo_height() // 2) self.video_popup.geometry(f'{popup_width}x{popup_height}+{x}+{y}') # Create label label = customtkinter.CTkLabel(self.video_popup, text="Image Augmentation Progress is Done\nDo you Want to Create video from these images?") label.grid(row=0, column=0, padx=20, pady=20) # Create buttons button_frame = customtkinter.CTkFrame(self.video_popup) button_frame.grid(row=1, column=0, pady=10) yes_button = customtkinter.CTkButton(button_frame, text="Yes", command=self.on_yes) yes_button.grid(row=0, column=0, padx=10) no_button = customtkinter.CTkButton(button_frame, text="No", command=self.on_no) no_button.grid(row=0, column=1, padx=10) def videoReady_button(self): self.startButton2.grid_forget() self.bind("", self.update_font_ready_button) rowCount = 0 self.custom_font = ("Frekuent-Mono", 15) self.colorLabel = customtkinter.CTkLabel(self.secondRow, text=f"Augmentations: ", font=self.custom_font) self.colorLabel.grid(row=0, column=1, sticky="nsw", pady=40, padx=(15, 0)) rowCount += 1 self.videoprogressBar = customtkinter.CTkProgressBar(self.secondRow, orientation="horizontal", height=20, progress_color="green", corner_radius=0) self.videoprogressBar.grid(row=0, column=2, pady=40, columnspan=2, sticky="nswe", padx=10) self.videoprogressBar.set(0) self.secondRow.update_idletasks() rowCount += 1 self.videoMain() def create_unique_variable_name(self, base_name, variables_dict): if base_name not in variables_dict: return base_name else: counter = 1 new_name = f"{base_name}{counter}" while new_name in variables_dict: counter += 1 new_name = f"{base_name}{counter}" return new_name def update_augmentation_label(self, value, a, temp, style): self.augmentationVar[a].set(value) self.augmentationLabel[a].configure(self.insideFrame[style], text=f"{temp}: {self.augmentationVar[a].get()}") def augmentedtoVideo(self): #setting folders because this is after image augmentation input folder is setted already self.image_input_folder = customtkinter.StringVar(value=fr"{self.imagesAugmented_filepath.get()}") self.augmentedvideo_output_folder = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\video") self.video_output_h265_folder = customtkinter.StringVar() #default fonts self.custom_font = ("Frekuent-Mono", 15) self.custom_font2 = ("Frekuent-Mono", 14) #browse button image settings self.browseImageSizeWidth = 23 self.browseImageSizeHeight = 23 self.title_image = customtkinter.CTkImage( light_image=Image.open("fileiconbt.png"), dark_image=Image.open("fileiconbt.png"), size=(self.browseImageSizeWidth, self.browseImageSizeHeight)) #first row of augmentedtoVideo self.firstRowFrame = customtkinter.CTkFrame(self.atv_frame) self.firstRowFrame.grid(row=0, column=0, pady=(10, 10), padx=30, sticky="nwes") self.firstRowFrame.grid_rowconfigure((0, 1, 2), weight=1) self.firstRowFrame.grid_columnconfigure(1, weight=1) #title of folder settings self.foldertitle = customtkinter.CTkLabel(self.firstRowFrame, text="Folder Settings:", font=self.custom_font2) self.foldertitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") #saving folder self.videoFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Video Saving Folder:", font=self.custom_font2) self.videoFolderLabel.grid(row=1, column=0, padx=(15, 15), pady=(20, 30), sticky="w") self.videoFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Video Saving Folder:", textvariable=self.augmentedvideo_output_folder, height=50, corner_radius=0) self.videoFolderEntry.grid(row=1, column=1, pady=(20, 30), sticky="ew", columnspan=1) self.videoFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, command=self.browse_augmentedvideo_output_folder, text="", height=50, width=60 , corner_radius=0) self.videoFolderBrowse.grid(row=1, column=2, pady=(20, 30), padx=(0, 20), columnspan=1) #second row of the augmentedtoVideo self.secondRowFrame = customtkinter.CTkFrame(self.atv_frame) self.secondRowFrame.grid(row=1, column=0, pady=(0, 10), padx=30, sticky="nwes", columnspan=2) self.secondRowFrame.grid_rowconfigure((0, 2, 3, 4, 8), weight=1) self.secondRowFrame.grid_columnconfigure((1, 2), weight=1) #title of the video settings self.videotitle = customtkinter.CTkLabel(self.secondRowFrame, text="Video Settings:", font=self.custom_font2) self.videotitle.grid(row=0, column=0, sticky="w", padx=10, pady=(5, 0)) #fps settings #deafult fps value self.frameRateVar = customtkinter.IntVar(value=15) self.frameRate = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_frame_label(value), height=50, button_corner_radius=4, corner_radius=0) self.frameRate.grid(row=2, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.frameRate.set(self.frameRateVar.get()) self.frameLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Frame Rate: {self.frameRateVar.get()}", font=self.custom_font2) self.frameLabel.grid(row=2, column=0, sticky="w", padx=(15, 0)) #image num settings self.imageNumVar = customtkinter.IntVar(value=3) self.imageNum = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_image_label(value), height=50, button_corner_radius=4, corner_radius=0) self.imageNum.grid(row=3, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.imageNum.set(self.imageNumVar.get()) self.imageNumLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Image Second: {self.imageNumVar.get()}", font=self.custom_font2) self.imageNumLabel.grid(row=3, column=0, sticky="w", padx=(15, 0)) #fake frame settings self.fakeFrameNumVar = customtkinter.IntVar(value=3) self.fakeFrameNum = customtkinter.CTkSlider(self.secondRowFrame, from_=0, to=60, command=lambda value: self.update_fakeframe_label(value), height=50, button_corner_radius=4, corner_radius=0) self.fakeFrameNum.grid(row=4, column=1, columnspan=2, sticky="we", padx=(10, 30), pady=20) self.fakeFrameNum.set(self.fakeFrameNumVar.get()) self.fakeFrameNumLabel = customtkinter.CTkLabel(self.secondRowFrame, text=f"Fake Frame Second: {self.fakeFrameNumVar.get()}", font=self.custom_font2) self.fakeFrameNumLabel.grid(row=4, column=0, sticky="w", padx=(15, 0)) #augmentedtoVideo start button self.startButton = customtkinter.CTkButton(self.secondRowFrame, text="Start", command=self.startAugmentedtoVideoProgress, font=self.custom_font2, height=30, width=150) self.startButton.grid(row=8, column=0, columnspan=3, padx=200, pady=10) def browse_augmentedvideo_output_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.augmentedvideo_output_folder.set(folder_path) def startAugmentedtoVideoProgress(self): thread = threading.Thread(target=self.augmentedtoVideoProgress) thread.start() #creating progress bar of image to video def augmentedtoVideoProgress(self): #update font size of augmented to video progress bars #creating third row of image to video self.thirdRowFrame = customtkinter.CTkFrame(self.atv_frame) self.thirdRowFrame.grid(row=2, column=0, pady=(0, 10), padx=30, sticky="nwes") self.thirdRowFrame.grid_rowconfigure((0, 1, 2), weight=1) self.thirdRowFrame.grid_columnconfigure(1, weight=1) #to calculate step size of progress bar image_folder = os.path.abspath(self.image_input_folder.get()) images = [img for img in os.listdir(image_folder) if img.lower().endswith('.jpg')] self.determinate = 100 / len(images) #progress bar title self.progresstitle = customtkinter.CTkLabel(self.thirdRowFrame, text="Progress Bars:", font=self.custom_font2) self.progresstitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") self.createVideoLabel = customtkinter.CTkLabel(self.thirdRowFrame, text="Video Creating Progress:", font=self.custom_font) self.createVideoLabel.grid(row=1, column=0, padx=(15, 5), pady=20, sticky="w") self.createVideoBar = customtkinter.CTkProgressBar(self.thirdRowFrame, orientation="horizontal", height=50, corner_radius=0, determinate_speed=self.determinate/2) self.createVideoBar.grid(row=1, column=1, sticky="we", pady=20, padx=(20,30)) self.createVideoBar.set(0) self.augmentation_values = [] #if output folder not exist create one if not os.path.exists(self.augmentedvideo_output_folder.get()): print(f"Creating output folder: {self.augmentedvideo_output_folder.get()}") os.makedirs(self.augmentedvideo_output_folder.get()) #base names of files base_filename_mp4 = 'output.mp4' base_filename_h265 = 'output_h265.mp4' output_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_mp4) output_h265_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_h265) #if name exist create different one index = 0 while os.path.exists(output_mp4): index += 1 base_filename_mp4 = f'output_{index}.mp4' output_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_mp4) #if name exist create different one index = 0 while os.path.exists(output_h265_mp4): index += 1 base_filename_h265 = f'output_h265_{index}.mp4' output_h265_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_h265) #calculate second of image and fakeframe imagesecond = self.frameRateVar.get() * self.imageNumVar.get() fakeframesecond = self.frameRateVar.get() * self.fakeFrameNumVar.get() image_folder = os.path.abspath(self.image_input_folder.get()) images = [img for img in os.listdir(image_folder) if img.lower().endswith('.jpg')] if not images: print(f"No JPEG images found in {self.image_input_folder.get()}. Exiting.") return frame = cv2.imread(os.path.join(image_folder, images[0])) if frame is None: print(f"Failed to load image: {images[0]}") return height, width, layers = frame.shape out = cv2.VideoWriter(output_mp4, cv2.VideoWriter_fourcc(*'mp4v'), self.frameRateVar.get(), (width, height)) black_frame = np.zeros((height, width, 3), dtype=np.uint8) for image in images: img_path = os.path.join(image_folder, image) img = cv2.imread(img_path) if img is None: print(f"Failed to load image: {img_path}. Skipping.") continue for _ in range(imagesecond): out.write(img) for _ in range(fakeframesecond): out.write(black_frame) self.createVideoBar.step() time.sleep(0.1) out.release() self.augmentedh265() def augmentedh265(self): base_filename_mp4 = 'output.mp4' base_filename_h265 = 'output_h265.mp4' output_h265_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_h265) index = 0 while os.path.exists(output_h265_mp4): index += 1 base_filename_h265 = f'output_h265_{index}.mp4' output_h265_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_h265) base_filename_mp4 = f'output_{index}.mp4' output_mp4 = os.path.join(self.augmentedvideo_output_folder.get(), base_filename_mp4) if os.path.exists(output_mp4): self.convert_to_h265(output_mp4, output_h265_mp4) else: print(f"Failed to create MP4 video at {output_mp4}") def imageMain(self): # Extra pixels for left, right, top, and bottom of the plate self.extraMargin = 10 # Values of augmentation function settings self.augmentationSettings = [] # Results is true or false values of augmentation types self.sResults = [] # Current_sublist holds values for results self.current_sublist = [] # General_list holds true or false values of augmentation style titles self.general_list = [] self.skip_values = False for value in self.augmentationVar.values(): self.augmentationSettings.append(value.get()) for item in self.augmentationTrueFalse: if item == '2': self.general_list.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) self.current_sublist = [] self.skip_values = False elif item == '3': self.general_list.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) self.skip_values = False elif not self.skip_values: self.current_sublist.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) image_paths = glob.glob(str(self.imagesFilePath) + "/*.jpg") total_images = len(image_paths) multi = len(self.augmentationTrueFalse)-len(self.general_list) progress_step = 100 / (total_images*multi) bar = 0 for image_index, image_path in enumerate(image_paths): try: fileNameParts = str(image_path).split("\\")[-1].split("_") locationInfos = fileNameParts[8].split("-") dateInfo = fileNameParts[2] resX, resY = Image.open(image_path).size if int(str(dateInfo).split("-")[1]) >= 7 and int(str(dateInfo).split("-")[2]) >= 5: bottom_crop_pixels = 50 resY -= bottom_crop_pixels else: bottom_crop_pixels = 30 resY -= bottom_crop_pixels imgBGR = cv2.imread(image_path) imgRGB = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2RGB) imgPIL = Image.fromarray(imgRGB) width, height = imgPIL.size croppedImg = imgPIL.crop((0, 0, width, height - bottom_crop_pixels)) imgCropped = cv2.cvtColor(np.array(croppedImg), cv2.COLOR_RGB2BGR) # croppedImgPIL = Image.fromarray(cv2.cvtColor(imgCropped, cv2.COLOR_BGR2RGB)) # # croppedImgPIL.show() # Debug print statements translate_x_min = -int(locationInfos[0]) + self.extraMargin translate_x_max = resX - int(locationInfos[2]) - self.extraMargin translate_y_min = -int(locationInfos[1]) + self.extraMargin translate_y_max = resY - int(locationInfos[3]) - self.extraMargin self.i = 0 def get_next_setting(): self.i val = self.i self.i += 1 return val self.augmentations_list = [ [ # Weather augmentations (self.crop_and_merge, [self.weather_fog_augmentation]), (self.crop_and_merge, [self.weather_rainy_augmentation]), (self.crop_and_merge, [self.weather_snowy_augmentation]), (self.crop_and_merge, [self.weather_cloud_augmentation]), (self.corrupt_fog_augmentation, []), (self.corrupt_snow_augmentation, []), (self.weather_rainy02_augmentation, [self.augmentationSettings[get_next_setting()], self.augmentationSettings[get_next_setting()], self.augmentationSettings[get_next_setting()]]), (self.weather_frost_augmentation, []) ], [ # Crop augmentations (self.crop_and_fill_augmentation, [translate_x_min, translate_x_max, translate_y_min, translate_y_max]), (self.rotate_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.shear, [self.augmentationSettings[get_next_setting()]]), (self.reflect_x_augmentation, [translate_x_min, translate_x_max]), (self.reflect_y_augmentation, [translate_y_min, translate_y_max]), (self.shear_x_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.shear_y_augmentation, [self.augmentationSettings[get_next_setting()]]), ], [ # Color augmentations (self.color_space_augmentation, []), (self.brightness_channels_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.hue_and_saturation_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.add_hue_and_saturation_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.change_color_space_augmentation, []), (self.gray_scale_augmentation, [self.augmentationSettings[get_next_setting()]]), (self.color_temperature_augmentation, []), (self.gamma_contrast_augmentation, []), (self.sigmoid_contrast_augmentation, []), (self.log_contrast_augmentation, []), (self.all_clahe_augmentation, []), (self.multiply_augmentation, []), (self.dropout2d_augmentation, []), (self.original_no_augmentation, []) ] ] for i in range(len(self.general_list)): for j in range(len(self.sResults[i])): if self.sResults[i][j] == "1": augmented_image_func, augmentation_params = self.augmentations_list[i][j] # Debug print statements # print(f"Augmentation function: {augmented_image_func}") # print(f"Parameters: {augmentation_params}") # Apply augmentation try: start_time = time.time() if len(augmentation_params) == 0: augmentedImage, augmentationStyle = augmented_image_func(imgCropped) else: augmentedImage, augmentationStyle = augmented_image_func(imgCropped, *augmentation_params) # croppedImgPIL = Image.fromarray(cv2.cvtColor(augmentedImage, cv2.COLOR_BGR2RGB)) # # croppedImgPIL.show() self.save_augmented_version_to_file(augmentedImage, augmentationStyle, resX, resY, self.imagesAugmented_filepath.get(), image_path) end_time = time.time() execution_time = end_time - start_time print(f"time {execution_time}") bar += progress_step print(bar) self.progressBar.set(bar/100) self.progressBar.update_idletasks() except ValueError as e: print(f"ValueError: {e}") print(f"Function call: {augmented_image_func} with parameters: {augmentation_params}") except Exception as e: print(f"Error applying augmentation: {e}") else: pass except Exception as e: print(f"Error processing image {image_path}: {e}") self.show_video_popup() def video_augmentation(self): self.video_filepath = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\images3") self.videoAugmented_filepath = customtkinter.StringVar(value=fr"C:\Users\cem\Desktop\PTS\augmentedImages") self.frame = {} self.label = {} self.var = {} self.switch = {} self.switch2 = {} self.switchLabel = {} self.videoAugmentations = [["Weather", "Fog02", "Rainy01", "Snowy02", "Cloudy", "Snowy", "Fog01", "Rainy02_Brightness_Drop width_Blur_1", "Frost"], ["Color", " Changed Color Space", "Brightness_Brightness_1", "Hue and Saturation_Saturation_1", "Hue and Saturation 2_Saturation_1", "Color Space", "Gray-Scale_Alpha_1", "Color Temperature", "Gamma Contrast", "Sigmoid Contrast", "Log Contrast", "All Clahe", "Multiply", "Dropout2D", "Original"] ] self.firstRowFrame = customtkinter.CTkFrame(self.va_frame) self.firstRowFrame.grid(row=0, column=0, sticky="nswe", padx=10 , pady=(10,10), columnspan = 2) # self.firstRowFrame.configure(fg_color="transparent") self.firstRowFrame.grid_columnconfigure(1, weight=1) self.firstRowFrame.grid_rowconfigure((0,1,2), weight=1) self.foldertitle = customtkinter.CTkLabel(self.firstRowFrame, text="Folder Settings:", font=self.custom_font2) self.foldertitle.grid(row=0, column=0, padx=10, pady=(5, 0), sticky="w") self.imageFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Original Video Folder:", font=self.custom_font) self.imageFolderLabel.grid(row=1, column=0, padx=(50, 10), pady=(15, 10), sticky="w") self.imageFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Original Video Folder:", textvariable=self.video_filepath, height=50, corner_radius=0) self.imageFolderEntry.grid(row=1, column=1, pady=(15, 10), sticky="we", columnspan=1) self.imageFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, width=60, height=50, command=self.browse_original_video_folder, text="", corner_radius=0) self.imageFolderBrowse.grid(row=1, column=2, pady=(15, 10), padx=5, columnspan=1, sticky="w") self.videoFolderLabel = customtkinter.CTkLabel(self.firstRowFrame, text="Augmented Video Folder:", font=self.custom_font) self.videoFolderLabel.grid(row=2, column=0, padx=(50, 10), pady=(10, 30), sticky="w") self.videoFolderEntry = customtkinter.CTkEntry(self.firstRowFrame, placeholder_text="Augmented Video Folder:", textvariable=self.videoAugmented_filepath, height=50, corner_radius=0) self.videoFolderEntry.grid(row=2, column=1, pady=(10, 30), sticky="we", columnspan=1) self.videoFolderBrowse = customtkinter.CTkButton(self.firstRowFrame, image=self.title_image, width=60, height=50, command=self.browse_augmented_video_folder, text="", corner_radius=0) self.videoFolderBrowse.grid(row=2, column=2, pady=(10, 30), padx=5, columnspan=1, sticky="w") self.videoAugmentation_values = self.switches(self.videoAugmentations, self.va_frame, self.va_ready_button_event, self.videoSecondRowFrame_nav) def video_augmentation_02(self): self.frame = {} self.augmentationVar = {} self.augmentationLabel = {} self.insideFrame = {} self.augmentationNames = [] self.titleLabel = {} self.imagesFilePath = self.video_filepath.get() self.augmentedFilePath = self.videoAugmented_filepath.get() #all augmentations true or false values if title is true = 2 false = 3 if subtitle is true = 1 false = 0 self.augmentationTrueFalse = [var.get() for var in self.videoAugmentation_values] self.firstRow = customtkinter.CTkFrame(self.va02_frame) self.firstRow.grid(row=0, column=0, sticky="nswe", padx=10, pady=10, columnspan=1) self.firstRow.grid_rowconfigure((0, 1), weight=1) self.firstRow.grid_columnconfigure((0, 1), weight=1) #all augmentation styles in one list self.augmentationsAllinOne = [] self.rowCount = 0 self.columnCount = 0 self.trackNumList = [] self.uniqueTrackNumList = [] self.styleNames =[] self.uniqueStyleNames = [] self.trackNumbers = [] self.frameNames = [] self.uniqueFrameNames = [] self.frameCount = 0 self.insideRowCount = 0 for x in range(len(self.videoAugmentations)): for y in range(len(self.videoAugmentations[x])): self.augmentationsAllinOne.append(self.videoAugmentations[x][y]) for i in range(len(self.augmentationTrueFalse)): if str(self.augmentationTrueFalse[i]) == str(self.augmentationsAllinOne[i]).split("_")[-1]: #to track augmentation title location self.trackNumber = i self.trackNumbers.append(i) while self.augmentationTrueFalse[self.trackNumber] == "1" or self.augmentationTrueFalse[self.trackNumber] == "0": # decrease i for find the augmentation title self.trackNumber -= 1 self.trackNumList.append(self.trackNumber) self.uniqueTrackNumList = set(self.trackNumList) for i in self.uniqueTrackNumList: self.frame_name = f"{self.augmentationsAllinOne[i]}" #creating scroable frame for each Augmentation Title self.frame[self.frame_name] = customtkinter.CTkScrollableFrame(self.firstRow, width=320, height=250, label_text=f"{self.augmentationsAllinOne[i]} Settings:", label_font=self.custom_font) self.frame[self.frame_name].grid(row=self.rowCount, column=self.columnCount, sticky="nswe", padx=(10, 10), pady=15, columnspan=1) self.frame[self.frame_name].grid_columnconfigure(0, weight=1) self.columnCount += 1 if self.columnCount > len(self.uniqueTrackNumList) / 2: self.rowCount += 1 self.columnCount = 0 self.frameNames.append(self.frame_name) self.uniqueFrameNames = set(self.frameNames) for j in self.trackNumbers: index_to_sublist = [] current_index = 0 for sublist in self.videoAugmentations: index_to_sublist.extend([current_index] * len(sublist)) current_index += 1 results = self.videoAugmentations[index_to_sublist[j]][0] if str(self.augmentationTrueFalse[j]) == str(self.augmentationsAllinOne[j]).split("_")[-1]: rowCount = len(str(self.augmentationsAllinOne[j]).split("_")[1:-1]) self.style = str(self.augmentationsAllinOne[j]).split("_")[0] self.insideRowCount = 0 self.frameCount += 1 self.insideFrame[self.style] = customtkinter.CTkFrame(self.frame[results], border_width=3) self.insideFrame[self.style].grid(row=self.frameCount, column=0, sticky="we", pady=15) self.insideFrame[self.style].grid_columnconfigure(1, weight=1) self.titleLabel[self.style] = customtkinter.CTkLabel(self.insideFrame[self.style], text=f"{self.style} Settings:", font=self.custom_font, anchor="w") self.titleLabel[self.style].grid(row=self.insideRowCount, column=0 , columnspan=2, sticky="we", pady=(5, 20), padx=5) self.insideRowCount += 1 for row in range(rowCount): temp1 = str(self.augmentationsAllinOne[j]).split("_")[1:-1][row] self.temp = self.create_unique_variable_name(temp1, self.augmentationVar) self.augmentationVar[self.temp] = customtkinter.IntVar(value=1) self.augmentationSlider = customtkinter.CTkSlider(self.insideFrame[self.style], from_=0, to=100, width=150, command=lambda value, a=self.temp, temp=temp1, style=self.style: self.update_augmentation_label(value, a, temp, style)) self.augmentationSlider.grid(row=row + 1, column=1, pady=15, sticky="we", padx=10) self.augmentationSlider.set(self.augmentationVar[self.temp].get()) self.augmentationLabel[self.temp] = customtkinter.CTkLabel(self.insideFrame[self.style], text=f"{temp1}: {self.augmentationVar[self.temp].get()}", font=self.custom_font) self.augmentationLabel[self.temp].grid(row=row + 1, column=0, sticky="w", pady=15, padx=(20, 40)) self.bind("", self.update_font_image2_augmentation) self.secondRow = customtkinter.CTkFrame(self.va02_frame) self.secondRow.grid(row=1, column=0, sticky="nswe", padx=10, pady=5, columnspan=1) self.secondRow.columnconfigure((2), weight=1) self.secondRow.rowconfigure(0, weight=1) # self.secondRow.configure(fg_color="transparent") self.startButton2 = customtkinter.CTkButton(self.secondRow, text="Ready", anchor="center", width=200, height=30, command=lambda: self.videoReady_button()) self.startButton2.grid(row=0, column=1, columnspan=2, sticky="we") def videoMain(self): # Extra pixels for left, right, top, and bottom of the plate self.extraMargin = 10 # Values of augmentation function settings self.videoaugmentationSettings = [] # Results is true or false values of augmentation types self.sResults = [] # Current_sublist holds values for results self.current_sublist = [] # General_list holds true or false values of augmentation style titles self.general_list = [] self.skip_values = False for value in self.augmentationVar.values(): self.videoaugmentationSettings.append(value.get()) for item in self.augmentationTrueFalse: if item == '2': self.general_list.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) self.current_sublist = [] self.skip_values = False elif item == '3': self.general_list.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) self.skip_values = False elif not self.skip_values: self.current_sublist.append(item) if self.current_sublist: self.sResults.append(self.current_sublist) video_paths = glob.glob(str(self.imagesFilePath) + "/*.mp4") for video_path in video_paths: try: cap = cv2.VideoCapture(str(video_path)) # Get video properties (frame width, height, frame rate) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = cap.get(cv2.CAP_PROP_FPS) # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for H.265, try 'hev1', 'HVC1', or others if needed out = cv2.VideoWriter(self.videoAugmented_filepath, fourcc, fps, (frame_width, frame_height)) # Read and write each frame while cap.isOpened(): ret, frame = cap.read() if not ret: break self.i = 0 def get_next_setting(): self.i val = self.i self.i += 1 return val self.augmentations_list = [ [ # Weather augmentations (self.crop_and_merge, [self.weather_fog_augmentation]), (self.crop_and_merge, [self.weather_rainy_augmentation]), (self.crop_and_merge, [self.weather_snowy_augmentation]), (self.crop_and_merge, [self.weather_cloud_augmentation]), (self.corrupt_fog_augmentation, []), (self.corrupt_snow_augmentation, []), (self.weather_rainy02_augmentation, [self.videoaugmentationSettings[get_next_setting()], self.videoaugmentationSettings[get_next_setting()], self.videoaugmentationSettings[get_next_setting()]]), (self.weather_frost_augmentation, []) ], [ # Color augmentations (self.color_space_augmentation, []), (self.brightness_channels_augmentation, [self.videoaugmentationSettings[get_next_setting()]]), (self.hue_and_saturation_augmentation, [self.videoaugmentationSettings[get_next_setting()]]), (self.add_hue_and_saturation_augmentation, [self.videoaugmentationSettings[get_next_setting()]]), (self.change_color_space_augmentation, []), (self.gray_scale_augmentation, [self.videoaugmentationSettings[get_next_setting()]]), (self.color_temperature_augmentation, []), (self.gamma_contrast_augmentation, []), (self.sigmoid_contrast_augmentation, []), (self.log_contrast_augmentation, []), (self.all_clahe_augmentation, []), (self.multiply_augmentation, []), (self.dropout2d_augmentation, []), (self.original_no_augmentation, []) ] ] for i in range(len(self.general_list)): for j in range(len(self.sResults[i])): if self.sResults[i][j] == "1": augmented_image_func, augmentation_params = self.augmentations_list[i][j] # Debug print statements # print(f"Augmentation function: {augmented_image_func}") # print(f"Parameters: {augmentation_params}") # Apply augmentation try: start_time = time.time() if len(augmentation_params) == 0: augmentedImage, augmentationStyle = augmented_image_func(frame) else: augmentedImage, augmentationStyle = augmented_image_func(frame, *augmentation_params) out.write(augmentedImage) end_time = time.time() execution_time = end_time - start_time print(f"time {execution_time}") except ValueError as e: print(f"ValueError: {e}") print(f"Function call: {augmented_image_func} with parameters: {augmentation_params}") except Exception as e: print(f"Error applying augmentation: {e}") else: pass cap.release() out.release() except Exception as e: print(f"Error processing image {video_path}: {e}") def browse_original_video_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.video_filepath.set(folder_path) def browse_augmented_video_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.videoAugmented_filepath.set(folder_path) def save_augmented_version_to_file(self, augmented_image, augmentation_style, resolution_x, resolution_y, imagesAugmented_filepath, image_path): augmented_img_pil = Image.fromarray(cv2.cvtColor(augmented_image, cv2.COLOR_BGR2RGB)) final_img = Image.new(mode='RGB', size=(resolution_x, resolution_y)) final_img.paste(augmented_img_pil, box=(0, 0)) save_path = os.path.join(imagesAugmented_filepath, f'{augmentation_style}_{os.path.basename(image_path)[:-4]}.jpg') final_img.save(save_path) def crop_and_fill_augmentation(self, image, translate_x_min, translate_x_max, translate_y_min, translate_y_max): translate_x = int(np.random.uniform(translate_x_min, translate_x_max)) translate_y = int(np.random.uniform(translate_y_min, translate_y_max)) augmentation = iaa.Sequential([ iaa.Affine( translate_px={ "x": (translate_x), "y": (translate_y) }, mode="edge" ) ]) return augmentation(image=image), "Crop and Fill" def rotate_augmentation(self, image, rotate): aug = iaa.Affine( rotate=(-rotate, rotate) ) return aug(image=image), "Rotate" def shear(self, image, shear_rate): aug = iaa.Affine( shear=(-shear_rate, shear_rate) ) return aug(image=image), "Shear" def reflect_x_augmentation(self, image, translate_x_min, translate_x_max): translate_x = int(np.random.uniform(translate_x_min, translate_x_max)) aug = iaa.Sequential([ iaa.Affine( translate_px={ "x": (translate_x), }, cval=(0, 255) , mode="wrap" ) ]) return aug(image=image), "ReflectX" def reflect_y_augmentation(self, image, translate_y_min, translate_y_max): translate_y = int(np.random.uniform(translate_y_min, translate_y_max)) aug = iaa.Sequential([ iaa.Affine( translate_px={ "y": (translate_y), }, cval=(0, 255) , mode="wrap" ) ]) return aug(image=image), "ReflectY" def shear_x_augmentation(self, image, shear_rate_for_x): aug = iaa.ShearX( (-shear_rate_for_x, shear_rate_for_x) ) return aug(image=image), "ShearX" def shear_y_augmentation(self, image, shear_rate_for_y): aug = iaa.ShearY( (-shear_rate_for_y, shear_rate_for_y) ) return aug(image=image), "ShearY" def crop_and_merge(self, image, augmentation_function): piece_width, piece_height = 960, 1280 img_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) large_width, large_height = img_pil.size merged_image = Image.new('RGB', (large_width, large_height)) cropped_pieces = [] for y in range(0, large_height, piece_height): for x in range(0, large_width, piece_width): box = (x, y, x + piece_width, y + piece_height) piece = img_pil.crop(box) cropped_pieces.append(piece) augmented_cropped_pieces = [] for piece in cropped_pieces: piece_np = np.array(piece) augmented_piece, self.augmentation_style = augmentation_function(piece_np) augmented_cropped_pieces.append(Image.fromarray(cv2.cvtColor(augmented_piece, cv2.COLOR_BGR2RGB))) for piece, (x, y) in zip(augmented_cropped_pieces, [(x, y) for y in range(0, large_height, piece_height) for x in range(0, large_width, piece_width)]): merged_image.paste(piece, (x, y)) return np.array(merged_image), self.augmentation_style def weather_rainy_augmentation(self, image): augmentation = iaa.Rain( drop_size=0.20, seed=1 ) rn = "Rainy01" return augmentation(image=image), rn def weather_rainy02_augmentation(self, image, brightness, drop_width, blur): transform = A.Compose( [A.RandomRain(brightness_coefficient=brightness, drop_width=drop_width, blur_value=blur, p=1)], ) random.seed(7) rn = "Rainy02" transformed = transform(image=image) return transformed["image"], rn def weather_fog_augmentation(self, image): augmentation = iaa.Fog( seed=2 ) return augmentation(image=image), "Fog01" def corrupt_fog_augmentation(self, image): augmentation = iaa.imgcorruptlike.Fog( severity=2 ) return augmentation(image=image), "Fog02" def corrupt_snow_augmentation(self, image): augmentation = iaa.imgcorruptlike.Snow( severity=2 ) return augmentation(image=image), "Snowy02" def weather_cloud_augmentation(self, image): augmentation = iaa.Clouds( seed=1 ) return augmentation(image=image), "Cloudy" def weather_snowy_augmentation(self, image): augmentation = iaa.Snowflakes( flake_size=(0.8, 0.95), speed=(0.001, 0.03), seed=1 ) return augmentation(image=image), "Snowy" def weather_frost_augmentation(self, image): aug = iaa.imgcorruptlike.Frost( severity=2, seed=1 ) return aug(image=image), "Frost" def original_no_augmentation(self, image): aug = iaa.WithBrightnessChannels(iaa.Add( )) return aug(image=image), "Original" def color_space_augmentation(self, image): aug = iaa.WithColorspace( to_colorspace="HSV", from_colorspace="RGB", children=iaa.WithChannels( 0, iaa.Add((0, 50)) ) ) return aug(image=image), "Color Space" def brightness_channels_augmentation(self, image, brightness): aug = iaa.WithBrightnessChannels(iaa.Add( (-brightness, brightness) )) return aug(image=image), "Brightness" def hue_and_saturation_augmentation(self, image, saturation): aug = iaa.WithHueAndSaturation( iaa.WithChannels(0, iaa.Add((0, saturation))) ) return aug(image=image), "Hue and Saturation" def add_hue_and_saturation_augmentation(self, image, saturation): aug = iaa.AddToHueAndSaturation( (-saturation, saturation), per_channel=True ) return aug(image=image), "Hue and Saturation 2" def change_color_space_augmentation(self, image): aug = iaa.Sequential([ iaa.ChangeColorspace(from_colorspace="RGB", to_colorspace="HSV"), iaa.WithChannels(0, iaa.Add((50, 100))), iaa.ChangeColorspace(from_colorspace="HSV", to_colorspace="RGB") ]) return aug(image=image), "Changed Color Space" def gray_scale_augmentation(self, image, alpha_for_grayscale): aug = iaa.Grayscale( alpha=(0.0, alpha_for_grayscale) ) return aug(image=image), "Gray Scale" def color_temperature_augmentation(self, image): aug = iaa.ChangeColorTemperature( (1100, 10000) ) return aug(image=image), "Color Temperature" def gamma_contrast_augmentation(self, image): aug = iaa.GammaContrast( (0.5, 2.0), per_channel=True ) return aug(image=image), "Gamma Contrast" def sigmoid_contrast_augmentation(self, image): aug = iaa.SigmoidContrast( gain=(3, 10), cutoff=(0.4, 0.6) ) return aug(image=image), "Sigmoid Contrast" def log_contrast_augmentation(self, image): aug = iaa.LogContrast( gain=(0.6, 1.4), per_channel=True ) return aug(image=image), "Log Contrast" def all_clahe_augmentation(self, image): aug = iaa.AllChannelsCLAHE( clip_limit=(1, 10), per_channel=True ) return aug(image=image), "All Clahe" def multiply_augmentation(self, image): aug = iaa.Multiply( (0.5, 1.5), per_channel=0.5 ) return aug(image=image), "Multiply" def dropout2d_augmentation(self, image): aug = iaa.Dropout2d( p=0.5 ) return aug(image=image), "Dropout2D" if __name__ == "__main__": app = App() app.mainloop()