如何将多个图像列表按列打印到 .PDF 文件?

问题描述

我有多个 ndarray 格式的图像列表(2 到 15 个),并希望在 .PDF 文件中按列显示它们,以便能够将这些列表相互比较。我已经看到了一些解决方案,但它们似乎对我不起作用,因为它们只考虑一个列表:

from fpdf import FPDF
pdf = FPDF()
# imagelist is the list with all image filenames
for image in IMG_LIST:
    pdf.add_page()
    pdf.image(image,x = None,y = None,w = 0,h = 0)
pdf.output("location.pdf","F")

我能够使用 matplotlib 生成我的图像,但更喜欢光滑的 .PDF 格式:

#Matplotlib approach
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import itertools
from pylab import rcParams

IMAGE_NUMBER=20

#Make model name list suitable for plot 
MODEL_NAMES2=list(itertools.chain.from_iterable(itertools.repeat(x,IMAGE_NUMBER) for x in MODEL_NAMES))
MODEL_NAMES3=[]
for i in MODEL_NAMES2:
  MODEL_NAMES3.append(i.split("/")[-1])

x = 10 #10
y = IMAGE_NUMBER

fig,axarr = plt.subplots(x,y)

for ax,im,name in zip(axarr.ravel(),images,MODEL_NAMES3):
    ax.imshow(im)
    ax.set_title(name)

#This will dictate the final image size,the first number is the width,the second number is the height
rcParams['figure.figsize'] = 500,20

图像大小不一,但如果这是先决条件,我可以调整它们的大小。 每个列表中按顺序排列的图像具有相同的大小。 任何指导方针或想法表示赞赏

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)