| 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' |
| ] |
| |
| |
| 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() |