python - Python/numpy 点列表到黑白图像区域
问题描述
我正在尝试将连续列表点(0 到 1 之间)转换为黑白图像,表示列表点下方/上方的区域。
plt.plot(points)
plt.ylabel('True val')
plt.show()
print("Points shape-->", points.shape)
我可以保存 matplotlib 生成的图像,但我认为这可能是一个讨厌的解决方法
最后,我想获得形状为 (224,224) 的图像,其中白色区域代表线下区域,黑色区域代表线上...
image_area = np.zeros((points.shape[0],points.shape[0],))
# ¿?
欢迎任何想法或建议如何处理它!感谢专家
解决方案
这是一个基本示例,说明如何做到这一点。由于切片需要整数,因此您可能必须先缩放原始数据。
import numpy as np
import matplotlib.pyplot as plt
# your 2D image
image_data = np.zeros((224, 224))
# your points. Here I am just using a random list of points
points = np.random.choice(224, size=224)
# loop over each column in the image and set the values
# under "points" equal to 1
for col in range(len(image_data[0])):
image_data[:points[col], col] = 1
# show the final image
plt.imshow(image_data, cmap='Greys')
plt.show()
推荐阅读
- c# - 将 ObservableCollection 绑定到 ListBox ItemsSource
- java - 如何使用 Android 对 Firestore 进行分页?
- magento - 如何在 Magento 中使用产品 URL 附加类别和子类别 slug
- string - 从特定列中的字符串中删除字符
- javascript - 用 Javascript 阻止 VPN 连接?
- java - 添加 checkstyle 作为预提交 git 钩子
- c++ - 默认模板参数在(部分特化)类模板的重载解析中的作用
- python - 加载配置文件后,selenium 打开了 Firefox,但部分选项仍然错误
- php - 如何在 PHP 对象数组中获取值
- android - 使用 Kotlin/Firebase 完成 Android Studio 代码 - 行为不端