Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在python中使用PIL合并文件夹中的多个图像时的颜色扩散_Python 3.x_Image_Merge_Python Imaging Library - Fatal编程技术网

Python 3.x 在python中使用PIL合并文件夹中的多个图像时的颜色扩散

Python 3.x 在python中使用PIL合并文件夹中的多个图像时的颜色扩散,python-3.x,image,merge,python-imaging-library,Python 3.x,Image,Merge,Python Imaging Library,我有一套17幅图像,其中一幅有一个突出显示的像素供我使用。但是,当我合并这17幅图像时,我得到了颜色,但它扩散出像素边界,我开始在黑色背景中看到一些彩色像素 我正在使用PIL库进行合并。我附上我的代码和图片作为参考。任何帮助都将不胜感激 import numpy as np import matplotlib.pyplot as plt import pandas as pd # Cretaing the Pixel array from PIL import Image from PIL

我有一套17幅图像,其中一幅有一个突出显示的像素供我使用。但是,当我合并这17幅图像时,我得到了颜色,但它扩散出像素边界,我开始在黑色背景中看到一些彩色像素

我正在使用PIL库进行合并。我附上我的代码和图片作为参考。任何帮助都将不胜感激

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Cretaing the Pixel array 

from PIL import Image
from PIL import ImageColor

img_path = '/Volumes/MY_PASSPORT/JRF/cancer_genome/gopal_gen/png_files/'

image_list = []
for entry in os.listdir(img_path):
    if entry.endswith('.png'):
        entry = int(entry.rstrip('.csv.png'))
        image_list.append(entry)
        image_list.sort()
list_img = []
for j in range(len(image_list)):
    stuff = str(image_list[j])+'.csv.png'
    list_img.append(stuff)
#print(list_img[0])

images = [Image.open(img_path+x) for x in list_img]
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
    #print(total_width, max_height)
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in images:
    new_im.paste(im, (x_offset,0))
    #print(im.size)
    x_offset += im.size[0]
    #print(x_offset)
    new_im.save(img_path+'final_result_image.jpg')
以下是合成图像: 第三列突出显示了一个像素

这里是放大部分的问题


JPEG格式有损-允许更改像素以缩小文件。如果您的图像是真实场景的传统照片,这通常并不重要。如果您的数据是块状的、计算机生成的图像,或者是分类过程中的一组类,那么如果您使用
JPEG
,则可能会出现严重错误


因此,答案是使用
PNG
(或潜在的
TIFF
)格式处理需要无损的图像。

我的答案解决了您的问题吗?如果是这样,请考虑接受它作为您的答案-点击空心蜱/支票旁边的选票计数。如果没有,请说出什么不起作用,以便我或其他人可以进一步帮助您。谢谢对不起,我有一段时间没有在这里活动。但是,这有帮助。谢谢@MarkSetchellI还有一个疑问。比方说,如果我有一个固定宽度的大图像,我只想在不同的列中粘贴图像(如上图),直到达到最大宽度,然后将下面的其余列粘贴到第二行。我该怎么做?像图像网格一样。没关系。谢谢任何寻找图像网格问题的人都可以参考和