我有多个 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
这些图像的大小并不相同,但如果这是先决条件,我可以调整它们的大小。每个列表按顺序排列的图像大小相同。任何指导方针或想法表示赞赏