Ref-Band / downsample_wb.py
Traver's picture
Upload 180 files
2147e2e verified
import os
import cv2
import glob
def downsample_image(image_path):
# 读取图像
img = cv2.imread(image_path)
if img is None:
print(f"Error reading image: {image_path}")
return None
# 获取原始尺寸
h, w = img.shape[:2]
# 下采样到一半大小
resized = cv2.resize(img, (w//2, h//2), interpolation=cv2.INTER_CUBIC)
return resized
def process_folders():
# 定义需要处理的文件夹
folders = [
'DIV2K_train_EDGE_disturbed',
'DIV2K_train_HR',
'DIV2K_train_LR_bicubic/X1' # LR_bicubic中的图像在X1子文件夹中
]
# 需要处理的图片名称
target_images = ['wb1.jpg', 'wb2.jpg', 'wb3.jpg']
for folder in folders:
print(f"\n处理文件夹: {folder}")
# 处理每个目标图片
for img_name in target_images:
img_path = os.path.join(folder, img_name)
if os.path.exists(img_path):
print(f"处理图片: {img_path}")
# 下采样图片
resized = downsample_image(img_path)
if resized is not None:
# 直接覆盖原图片
cv2.imwrite(img_path, resized)
print(f"已完成下采样: {img_path}")
else:
print(f"找不到图片: {img_path}")
if __name__ == '__main__':
process_folders()