fromPILimportImage# 打开完整的拼接图像full_image=Image.open(r"C:\Users\scofi\Desktop\pintu\flag.jpg")full_width,full_height=full_image.size# 定义每个小图像的尺寸和间距small_width,small_height=300,225padding=25border=25# 添加白色边框大小# 计算行列数num_cols=(full_width-border)//(small_width+padding)num_rows=(full_height-border)//(small_height+padding)print(f"总共有 {num_rows} 行和 {num_cols} 列小图像.")# 分割并保存小图像、counter=1forrowinrange(num_rows):forcolinrange(num_cols):left=border+col*(small_width+padding)top=border+row*(small_height+padding)right=left+small_widthbottom=top+small_heightprint(f"正在处理第 {counter} 张小图像:左上角坐标 ({left}, {top}), 右下角坐标 ({right}, {bottom})")# Crop the small imagesmall_image=full_image.crop((left,top,right,bottom))# Convert to RGB mode (if not already in RGB)ifsmall_image.mode!='RGB':small_image=small_image.convert('RGB')# Save the small imagesmall_image.save(r"C:\Users\scofi\Desktop\pintu\{counter}.jpg".format(counter=counter))counter+=1print("所有小图像已保存完成.")