如何从URL中检索拆分为网格的图像,并将其合并为一个网格?

2024-04-25 09:00:39 发布

您现在位置:Python中文网/ 问答频道 /正文

您将如何检索从六个不同URL拆分为六个独立图像的图像,并将它们合并为一个单独的URL

因此,有一个图像被拆分成如下所示的网格,其中每个图像位于单独的url上。url不以.jpg.png或任何文件类型结尾

|-----------|-----------|
|  Col 0    |   Col 1   |
|  Row 0    |   Row 0   |          |-----------|
|-----------|-----------|          |           |
|  Col 0    |   Col 1   |          |   New     |
|  Row 1    |   Row 1   |   ==>>   |   single  |
|-----------|-----------|          |   image   |
|  Col 0    |   Col 1   |          |-----------|
|  Row 2    |   Row 2   |
|-----------|-----------|

我已经看到一些单独的问题,我可以结合起来解决这个问题,但我无法让他们一起工作。这应该适用于几百张图片


Tags: 图像image网格urlnewpng结尾图片
1条回答
网友
1楼 · 发布于 2024-04-25 09:00:39

由于您没有提供任何图片或链接,我将在此处放置一些示例图片,我可以下载并在回答中使用这些图片:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

#!/usr/bin/env python3

import numpy as np
from imageio import imread, imwrite

# Read the 6 images, taking just the first 3 RGB channels of each (discarding any alpha channel)
im1 = imread('https://i.stack.imgur.com/h5Cyb.png')[...,:3]
im2 = imread('https://i.stack.imgur.com/nYPxr.png')[...,:3]
im3 = imread('https://i.stack.imgur.com/APnAq.png')[...,:3]
im4 = imread('https://i.stack.imgur.com/fy232.png')[...,:3]
im5 = imread('https://i.stack.imgur.com/nIXhf.png')[...,:3]
im6 = imread('https://i.stack.imgur.com/WsQnX.png')[...,:3]

# Vertically stack 3 images to make left column, and 3 more to make right column
Lcol = np.vstack((im1,im2,im3))
Rcol = np.vstack((im4,im5,im6))

# Horizontally stack 2 columns to make result
result = np.hstack((Lcol,Rcol))

# Save result to disk
imwrite('result.jpg', result)

结果

enter image description here

相关问题 更多 >