16 lines
686 B
Python
16 lines
686 B
Python
import cv2
|
|
import numpy as np
|
|
import os
|
|
from PIL import Image,ImageEnhance
|
|
from PIL import Image
|
|
import os
|
|
folder_path = 'C:/workspace/le-yolo/data/images/train'
|
|
for filename in os.listdir(folder_path):
|
|
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
|
|
img_path = os.path.join(folder_path, filename)
|
|
img = Image.open(img_path)
|
|
gray_img = img.convert('L')
|
|
new_filename = os.path.splitext(filename)[0] + '_gray.jpg' # 修改为新文件名,如 "image_gray.jpg"
|
|
new_img_path = os.path.join(folder_path, new_filename)
|
|
gray_img.save(new_img_path)
|
|
print(f"已将 {filename} 转换为灰度图像并保存") |