可以使用PIL库来实现提取两张图片中像素坐标相同的部分。

以下是一个示例程序:

from PIL import Image

def extract_same_pixels(image1_path, image2_path):
    # 打开并加载图片
    image1 = Image.open(image1_path)
    image2 = Image.open(image2_path)

    # 获取图片的尺寸
    width, height = image1.size

    # 创建新的图片对象
    new_image = Image.new("RGB", (width, height))

    # 遍历每个像素点
    for x in range(width):
        for y in range(height):
            # 获取像素坐标相同的像素值
            pixel1 = image1.getpixel((x, y))
            pixel2 = image2.getpixel((x, y))
            
            # 判断像素值是否相同
            if pixel1 == pixel2:
                new_image.putpixel((x, y), pixel1)
    
    # 保存提取的部分为新图片
    new_image.save("result.png")

# 示例用法
extract_same_pixels("image1.png", "image2.png")

上述程序将提取两张图片中像素坐标相同的部分,并保存为名为"result.png"的新图片

写一个python程序提取两图中像素坐标相同的部分

原文地址: http://www.cveoy.top/t/topic/iBPa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录