import os from PIL import Image from Load_process.file_processing import Process_File from utils.Stomach_Config import Image_Enhance def make_label_list(length, content): '''製作label的列表''' label_list = [] for i in range(length): label_list.append(content) return label_list def Read_Image_Root_And_Image_Enhance(Image_Roots, Save_Root): '''讀取Image Root''' i = 0 file = Process_File() for Image_Root in Image_Roots: try: Images = Image.open(Image_Root).convert("RGB") Images = Image_Enhance["gamma"](Images, Image_Enhance["Gamma_Value"]) for j in range(5): Images = Image_Enhance["Median"](Images) Images = Image_Enhance["Shapen"](Images) file.JudgeRoot_MakeDir(Save_Root) # 使用原始檔名而不是索引編號 original_filename = os.path.basename(Image_Root) path = file.Make_Save_Root(original_filename, Save_Root) Images.save(path) # Image = cv2.imread(Image_Root, cv2.IMREAD_COLOR) # 讀檔(彩色) # Image = cv2.cvtColor(Image, cv2.COLOR_BGR2RGB) except Exception as e: print(e) i += 1 print("已處理 " + str(i) + " 張圖片") pass