微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何将多个图像列表按列打印到 .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 举报,一经查实,本站将立刻删除。