|
|
import os
|
|
|
import cv2
|
|
|
import numpy as np
|
|
|
import shutil
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
source_root = r"G:\datasets\lolblurtest\test\high_sharp_original"
|
|
|
|
|
|
exp_root = r"G:\IR_Experiment\Order_Test"
|
|
|
|
|
|
|
|
|
target_input_dir = os.path.join(exp_root, "input_dark_noisy")
|
|
|
os.makedirs(target_input_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
def degradate_image(img):
|
|
|
|
|
|
img = img.astype(np.float32) * 0.2
|
|
|
|
|
|
|
|
|
noise = np.random.normal(0, 15, img.shape)
|
|
|
img = img + noise
|
|
|
|
|
|
|
|
|
img = np.clip(img, 0, 255).astype(np.uint8)
|
|
|
return img
|
|
|
|
|
|
|
|
|
print("🚀 开始构建数据集...")
|
|
|
count = 0
|
|
|
|
|
|
|
|
|
for root, dirs, files in os.walk(source_root):
|
|
|
|
|
|
img_files = [f for f in files if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
|
|
|
|
|
if img_files:
|
|
|
|
|
|
file_name = img_files[0]
|
|
|
src_path = os.path.join(root, file_name)
|
|
|
|
|
|
|
|
|
img = cv2.imread(src_path)
|
|
|
if img is None: continue
|
|
|
|
|
|
|
|
|
bad_img = degradate_image(img)
|
|
|
|
|
|
|
|
|
folder_name = os.path.basename(root)
|
|
|
save_name = f"{folder_name}_{file_name}"
|
|
|
save_path = os.path.join(target_input_dir, save_name)
|
|
|
|
|
|
cv2.imwrite(save_path, bad_img)
|
|
|
count += 1
|
|
|
print(f"[{count}] 处理: {save_name}")
|
|
|
|
|
|
|
|
|
if count >= 8:
|
|
|
break
|
|
|
|
|
|
print(f"✅ 数据集准备完毕!共 {count} 张。")
|
|
|
print(f"📂 坏图位置: {target_input_dir}") |