ptthon拼图
from PIL import Image # 打开图像文件 image = Image.open("input_image.jpg") # 获取图像的宽度和高度 width, height = image.size # 创建一个新的图像,将原始图像复制到其上 new_image = Image.new("RGB", (width, height)) for x in range(width): for y in range(height): new_image.putpixel((x, y), image.getpixel((x, y))) # 保存新图像 new_image.save("output_image.jpg")
# 加载图像文件并将其分割成N块 image = Image.open("output_image.jpg") width, height = image.size num_blocks = 4 block_size = min(width, height) // num_blocks x_blocks = [int(x * block_size) for x in range(num_blocks)] y_blocks = [int(y * block_size) for y in range(num_blocks)] blocks = [] for x in x_blocks: for y in y_blocks: block = image.crop((x, y, x + block_size, y + block_size)) blocks.append(block)
===========
标签:blocks,width,python,image,height,拼图,block,size From: https://www.cnblogs.com/herd/p/17539377.html