【发布时间】:2019-07-05 02:19:12
【问题描述】:
我正在尝试使用 matplotlib、os.path 和 numpy 裁剪图像(从学校图片中裁剪背景)。
我的想法是将图像分割成除我需要的部分之外的正方形,然后操纵 Alpha 通道以使这些区域透明,这样我剩下的就是我需要的部分。我开始编写代码,但遇到了相同的错误消息。
我尝试制作某种圆形蒙版来裁剪脸部,但蒙版的概念对我来说仍然很陌生,所以我认为这会更容易。
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img, interpolation='none')
# Show the figure on the screen
row = len(img)
column = len(img[0])
for row in range(0, 231) :
for column in range(0, 330) :
img[row][column] = [0, 0, 0, 0]
fig.show()
Results: 26 for row in range(0, 231) :
27 for column in range(0, 330) :
---> 28 img[row][column] = [0, 0, 0]
29
30
IndexError: index 288 is out of bounds for axis 0 with size 288
【问题讨论】:
-
您确定要在 matplotlib 中执行此操作吗?我认为会有更好的工具可用于这项工作。例如,看看this。
标签: python image matplotlib rgb alpha