| import cv2 |
| import os |
| import shutil |
| import numpy as np |
| from tqdm import tqdm |
|
|
| def apply_clahe_to_image(image, clip_limit=2.0, tile_grid_size=(8, 8)): |
| """ |
| ์ด๋ฏธ์ง์ CLAHE๋ฅผ ์ ์ฉํฉ๋๋ค (LAB ์์ ๊ณต๊ฐ์ L ์ฑ๋ ์ฌ์ฉ). |
| ์์(RGB) ์ ๋ณด๋ ์ ์ง๋ฉ๋๋ค. |
| """ |
| if image is None: |
| return None |
| |
| |
| lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) |
| l, a, b = cv2.split(lab) |
| |
| |
| clahe = cv2.createCLAHE(clipLimit=clip_limit, tileGridSize=tile_grid_size) |
| l_clahe = clahe.apply(l) |
| |
| |
| lab_merge = cv2.merge((l_clahe, a, b)) |
| final_img = cv2.cvtColor(lab_merge, cv2.COLOR_LAB2BGR) |
| |
| return final_img |
|
|
| def process_dataset(src_root, dst_root): |
| |
| img_extensions = ['.jpg', '.jpeg', '.png', '.bmp', '.tif', '.tiff'] |
| |
| print(f"Dataset Processing: {src_root} -> {dst_root}") |
| |
| |
| for root, dirs, files in os.walk(src_root): |
| |
| rel_path = os.path.relpath(root, src_root) |
| current_dst_dir = os.path.join(dst_root, rel_path) |
| |
| |
| os.makedirs(current_dst_dir, exist_ok=True) |
| |
| |
| for file in tqdm(files, desc=f"Processing {rel_path}", leave=False): |
| src_file_path = os.path.join(root, file) |
| dst_file_path = os.path.join(current_dst_dir, file) |
| |
| file_ext = os.path.splitext(file)[1].lower() |
| |
| if file_ext in img_extensions: |
| |
| img = cv2.imread(src_file_path) |
| |
| new_img = apply_clahe_to_image(img, clip_limit=2.0, tile_grid_size=(8,8)) |
| |
| if new_img is not None: |
| cv2.imwrite(dst_file_path, new_img) |
| else: |
| print(f"Warning: Could not read image {src_file_path}") |
| |
| else: |
| |
| shutil.copy2(src_file_path, dst_file_path) |
|
|
| print("\n" + "="*50) |
| print("โ
๋ชจ๋ ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋์์ต๋๋ค.") |
| print(f"์ ์ฅ ์์น: {os.path.abspath(dst_root)}") |
| print("โ ๏ธ ์ฃผ์: ์๋ก ์์ฑ๋ ํด๋ ์์ 'exdark.yaml' ํ์ผ ๋ด๋ถ ๊ฒฝ๋ก(path)๋ฅผ ํ์ธํด์ฃผ์ธ์!") |
| print("="*50) |
|
|
| if __name__ == '__main__': |
| |
| SOURCE_DIR = "./CNTSSS" |
| |
| |
| DEST_DIR = "./CNTSSS_CLAHE" |
| |
| if not os.path.exists(SOURCE_DIR): |
| print(f"Error: ์๋ณธ ๊ฒฝ๋ก '{SOURCE_DIR}'๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.") |
| else: |
| process_dataset(SOURCE_DIR, DEST_DIR) |