Python 将numpy 32int保存到多层tiff中

Python 将numpy 32int保存到多层tiff中,python,numpy,tiff,Python,Numpy,Tiff,我正在研究科学图像,其中有一种称为“线”的东西有一系列(n)灰度图像。 我所做的是用特定的颜色给每一行的图像上色,然后将每一行对应的图像合并在一起(即,我将每一行的图像_0合并为一个图像,然后将每一行的图像_1合并为一个图像,依此类推)。 结果是(n)个图像的彩色合并序列 我现在的目标是将这个序列保存到一个tiff文件中,到目前为止我还不能保存 def load_image(infilename): img = Image.open(infilename) img.load()

我正在研究科学图像,其中有一种称为“线”的东西有一系列(n)灰度图像。 我所做的是用特定的颜色给每一行的图像上色,然后将每一行对应的图像合并在一起(即,我将每一行的图像_0合并为一个图像,然后将每一行的图像_1合并为一个图像,依此类推)。 结果是(n)个图像的彩色合并序列

我现在的目标是将这个序列保存到一个tiff文件中,到目前为止我还不能保存

def load_image(infilename):
    img = Image.open(infilename)
    img.load()
    data = np.asarray(img, dtype="int32")
    return data

def merge_lines_images(lines, colors):
    rotations_count = len(lines[0])
    layers = []
    for rotation in range(0, rotations_count):
        images_to_merge = []
        for line in lines:
            img = load_image(line[rotation])
            images_to_merge.append(img)

        colored_images = []
        for img_index, img in enumerate(images_to_merge):
            color = colors[img_index]

            r = img * color[0] / 255

            g = img * color[1] / 255

            b = img * color[2] / 255

            rgb = np.dstack((r,g,b))
            colored_images.append(rgb)

        merged_image = np.zeros(colored_images[0].shape)

        for img in colored_images:
            merged_image += img

        clipped = np.clip(merged_image, 0, 255, out=merged_image)

        layers.append(clipped)
如何将“层”阵列保存到一个多层tiff文件中


非常感谢

我不知道你所说的
32int
是什么意思。尝试:
使用tifffile.TiffWriter('layers.tif')作为tif:for layers中的图像:tif.save(image.astype('uint8'),photometric='rgb')
成功!!非常感谢:D