【发布时间】:2021-03-02 06:17:17
【问题描述】:
【问题讨论】:
-
使
M和N都等于 2 肯定不是阐明您想要什么的最佳方式!
【问题讨论】:
M 和 N 都等于 2 肯定不是阐明您想要什么的最佳方式!
在 numpy 中,您可以像分割数组一样分割图片。
以下是您的图片示例:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
img = np.array(Image.open("cat.jpg"))
plt.imshow(img)
xs = img.shape[0]//2 # division lines for the picture
ys = img.shape[1]//2
# now slice up the image (in a shape that works well with subplots)
splits = [[img[0:xs, 0:ys], img[0:xs, ys:]], [img[xs:, 0:ys], img[xs:, ys:]]]
fig, axs = plt.subplots(2, 2)
for i in range(2):
for j in range(2):
axs[i][j].imshow(splits[i][j])
请记住,此处的拆分是 视图 到原始数组中,而不是包含新数据的数组,因此您对视图所做的更改将更改原始数据。如果你不想这样,你可以在对数组进行切片后复制数据。
【讨论】: