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 from tqdm import tqdm import threading import time from PIL import Image from functools import partial np.complex = np.complex128 np.bool = np.bool_ class App(customtkinter.CTk): def __init__(self): super().__init__() self.color_augmentations = [] self.crop_augmentations = [] self.weather_augmentations = [] self.build_file = 'build_number.txt' self.program_name = str(__file__) self.version = self.program_name.split("\\")[-1][:-3] self.build_number = int(self.version.split(".")[2]) self.build_number_main() build_number = self.get_build_number(self.build_file) now = datetime.now() formatted_now = now.strftime('%Y%m%d.%H%M00') 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) self.title("Data Augmentation") self.geometry("940x750") # self.resizable(False,False) self.row = 4 self.grid_rowconfigure(0, weight=1) self.grid_columnconfigure((1,2), weight=1) self.logo_image = customtkinter.CTkImage(Image.open("icon3.ico"), size=(100, 100)) 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(5, weight=1) 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) 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) self.da_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, width=50, border_spacing=10, text="Data Augmentation", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.da_button_event) self.da_button.grid(row=2, column=0, sticky="ew", columnspan=2) 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) self.secondRowFrame_nav = customtkinter.CTkFrame(self.navigation_frame) self.secondRowFrame_nav.grid(row=3, column=0) self.secondRowFrame_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)) 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) 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)) self.da_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.da_frame.grid_columnconfigure((0, 1), weight=1) self.da_frame.grid_rowconfigure((0, 1, 2, 3), weight=1) self.da02_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent") self.da02_frame.grid_rowconfigure((0, 1), weight=1) self.da02_frame.grid_columnconfigure(0, weight=1) 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) self.select_frame_by_name("itv") self.itv_button_event() 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 def set_build_number(self, file_path, build_number): with open(file_path, 'w') as file: file.write(str(build_number)) 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) def update_font_size(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)) 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)) def update_font_data_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)) def update_font_data2_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)) self.startButton2.configure(font= ("Frekuent-Mono", font_size)) self.colorLabel.configure(font= ("Frekuent-Mono", font_size)) def select_frame_by_name(self, name): self.itv_button.configure(fg_color=("gray75", "gray25") if name == "itv" else "transparent") self.da_button.configure(fg_color=("gray75", "gray25") if name == "da" 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 == "da": self.da_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.da_frame.grid_forget() if name == "da02": self.da02_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.da02_frame.grid_forget() if name == "va": self.va_frame.grid(row=0, column=1, sticky="nsew", columnspan = 2) else: self.va_frame.grid_forget() def itv_button_event(self): self.select_frame_by_name("itv") self.image_to_video() self.secondRowFrame_nav.grid_forget() def da_button_event(self): self.row = 4 self.data_augmentation() self.secondRowFrame_nav.grid(row=3, column=0) self.select_frame_by_name("da") def va_button_event(self): self.row = 3 self.video_augmentation() self.select_frame_by_name("va") self.secondRowFrame_nav.grid_forget() def da_ready_button_event(self): self.data_augmentation_02() self.select_frame_by_name("da02") self.secondRowFrame_nav.grid_forget() def change_scaling_event(self, new_scaling: str): new_scaling_float = int(new_scaling.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) def change_appearance_mode_event(self, new_appearance_mode): customtkinter.set_appearance_mode(new_appearance_mode) def image_to_video(self): self.bind("", self.update_font_size) 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") self.video_output_h265_folder = customtkinter.StringVar() self.custom_font = ("Frekuent-Mono", 15) self.custom_font2 = ("Frekuent-Mono", 14) 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)) 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) 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="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) 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) 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) 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)) 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)) 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)) 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)) self.startButton = customtkinter.CTkButton(self.secondRowFrame, text="Start", command=self.start_progress_bars, font=self.custom_font2, height=30, width=150) self.startButton.grid(row=8, column=0, columnspan=3, padx=200, pady=10) def start_progress_bars(self): thread = threading.Thread(target=self.progressBars) thread.start() def progressBars(self): self.bind("", self.update_font_video_progress, self.update_font_size) 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) 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) 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 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_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) 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) 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) 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_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) 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) 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 browse_h265_output_folder(self): folder_path = filedialog.askdirectory() if folder_path: self.video_output_h265_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 data_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.augmentations = [["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", "Color-Space", "Brightness_Brightness_1", "Hue and Saturation_Saturation_1", "Hue and Saturation 2", "Color Space", "Gray-Scale_Alpha_1", "Color-Temperature", "Gamma-Contrast", "Sigmoid-Contrast", "Log-Contrast", "All Clahe", "Multiply", "Dropout2D", "Original"] ] self.firstRowFrame = customtkinter.CTkFrame(self.da_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.augmentation_values = self.switches(self.augmentations) def switches(self, augmentations): self.frame_count = 0 column_count = 0 row_count = 0 self.secondRowFrame = customtkinter.CTkFrame(self.da_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(self.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( self.secondRowFrame_nav, 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.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="w") 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: self.show_popup(name)) self.switchLabel[self.type_name].bind("", self.hide_popup) self.popup_window = None self.frame_count += 1 self.bind("", self.update_font_data_augmentation) self.thirdRowFrame = customtkinter.CTkFrame(self.da_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=self.da_ready_button_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): if not self.popup_window: self.create_popup_window() 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): 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 data_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.augmentation_values] self.firstRow = customtkinter.CTkFrame(self.da02_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.augmentations)): for y in range(len(self.augmentations[x])): self.augmentationsAllinOne.append(self.augmentations[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.augmentations: index_to_sublist.extend([current_index] * len(sublist)) current_index += 1 results = self.augmentations[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_data2_augmentation) self.secondRow = customtkinter.CTkFrame(self.da02_frame) self.secondRow.grid(row=1, column=0, sticky="we", 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.ready_button()) self.startButton2.grid(row=0, column=1, columnspan=2, sticky="we") def ready_button(self): self.startButton2.grid_forget() 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.progressBar = customtkinter.CTkProgressBar(self.secondRow, orientation="horizontal", height=20, progress_color="green", corner_radius=0) self.progressBar.grid(row=0, column=2, pady=40, columnspan=2, sticky="nswe", padx=10) self.progressBar.set(0) self.secondRow.update_idletasks() rowCount += 1 self.main() 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 main(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) progress_step = 1 / total_images 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.weather_fog_augmentation = lambda img: (img, "fog") self.weather_rainy_augmentation = lambda img: (img, "rainy") self.weather_snowy_augmentation = lambda img: (img, "snowy") self.weather_cloud_augmentation = lambda img: (img, "cloud") self.corrupt_fog_augmentation = lambda img: (img, "corrupt_fog") self.corrupt_snow_augmentation = lambda img: (img, "corrupt_snow") self.weather_rainy02_augmentation = lambda img, p1, p2, p3: (img, "rainy02") self.weather_frost_augmentation = lambda img: (img, "frost") 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[0], self.augmentationSettings[1], self.augmentationSettings[2]]), (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[3]]), (self.shear, [self.augmentationSettings[4]]), (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[5]]), (self.shear_y_augmentation, [self.augmentationSettings[6]]), ], [ # Color augmentations (self.color_space_augmentation, []), (self.brightness_channels_augmentation, [self.augmentationSettings[7]]), (self.hue_and_saturation_augmentation, [self.augmentationSettings[8]]), (self.add_hue_and_saturation_augmentation, [self.augmentationSettings[7]]), (self.change_color_space_augmentation, []), (self.gray_scale_augmentation, [self.augmentationSettings[9]]), (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: if len(augmentation_params) == 0: augmentedImage, augmentationStyle = augmented_image_func(imgCropped) else: augmentedImage, augmentationStyle = augmented_image_func(imgCropped, *augmentation_params) cv2.imwrite(f"debug_{augmentationStyle}.jpg", cv2.cvtColor(np.array(augmentedImage), cv2.COLOR_RGB2BGR)) self.save_augmented_version_to_file(augmentedImage, augmentationStyle, resX, resY, self.imagesAugmented_filepath.get(), image_path) 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 self.progressBar.set(progress_step * (image_index + 1)) self.progressBar.update_idletasks() except Exception as e: print(f"Error processing image {image_path}: {e}") 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.augmen = [["Weather_1", "Fog01", "Fog02", "Rainy01", "Rainy02_Brightness_Drop width_Blur_1", "Snowy", "Cloudy", "Frost"], ["Color_1", "Color-Space", "Dropout2D", "Brightness_Brightness_1", "Hue and Saturation_Saturation_1", "Gray-Scale_Alpha_1", "Color-Temperature", "Gamma-Contrast", "Sigmoid-Contrast", "Log-Contrast", "All Clahe", "Multiply", "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_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") a = self.switches(self.augmen) def browse_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), "cropped_and_filled" def rotate_augmentation(self, image, rotate): aug = iaa.Affine( rotate=(-rotate, rotate) ) return aug(image=image), "cropped" 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), "reflect_x" 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), "reflect_y" 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), "shear_x" 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), "shear_y" 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)) aug = iaa.WithBrightnessChannels(iaa.Add( )) return aug(image=merged_image), self.augmentation_style def weather_rainy_augmentation(self, image): augmentation = iaa.Rain( drop_size=0.20, seed=1 ) rn = "rainy_weather" 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_weather" transformed = transform(image=image) return transformed["image"], rn def weather_fog_augmentation(self, image): augmentation = iaa.Fog( seed=2 ) return augmentation(image=image), "foggy_weather" def corrupt_fog_augmentation(self, image): augmentation = iaa.imgcorruptlike.Fog( severity=2 ) return augmentation(image=image), "corrupt_fog" def corrupt_snow_augmentation(self, image): augmentation = iaa.imgcorruptlike.Snow( severity=2 ) return augmentation(image=image), "corrupt_snow" def weather_cloud_augmentation(self, image): augmentation = iaa.Clouds( seed=1 ) return augmentation(image=image), "cloudy_weather" 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_weather" def weather_frost_augmentation(self, image): aug = iaa.imgcorruptlike.Frost( severity=2, seed=1 ) return aug(image=image), "frost_weather" 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-channel" 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), "added-hue-and-saturation" 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), "dropout-2d" if __name__ == "__main__": app = App() app.mainloop()