First
This commit is contained in:
29
裁剪EM18下侧.py
Normal file
29
裁剪EM18下侧.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
# === 参数配置 ===
|
||||
input_folder = r"D:\PythonProject\AutoAnno\还没clip" # 原图所在文件夹
|
||||
output_folder = r"D:\PythonProject\AutoAnno\test_images" # 裁剪后保存的文件夹
|
||||
crop_right_pixels = 1450 # 要裁掉的右侧像素数量
|
||||
|
||||
# 如果输出文件夹不存在则创建
|
||||
os.makedirs(output_folder, exist_ok=True)
|
||||
|
||||
# 遍历文件夹中的所有图片文件
|
||||
for filename in os.listdir(input_folder):
|
||||
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.tif', '.tiff')):
|
||||
img_path = os.path.join(input_folder, filename)
|
||||
img = Image.open(img_path)
|
||||
width, height = img.size
|
||||
|
||||
# 定义裁剪区域:(left, upper, right, lower)
|
||||
crop_box = (0, 0, width, height- crop_right_pixels)
|
||||
cropped_img = img.crop(crop_box)
|
||||
|
||||
# 保存结果
|
||||
output_path = os.path.join(output_folder, filename)
|
||||
cropped_img.save(output_path)
|
||||
|
||||
print(f"已裁剪: {filename} -> 下侧去掉 {crop_right_pixels} 像素")
|
||||
|
||||
print("✅ 批量裁剪完成!")
|
||||
Reference in New Issue
Block a user