python图像曲线坐标提取写入excel
时间: 2023-05-18 17:05:41 浏览: 144
这里提供一种实现方式,使用Python的Pillow库和openpyxl库。
首先,需要安装这两个库:
```
pip install Pillow
pip install openpyxl
```
然后,我们可以先读取图片,使用Pillow库中的Image模块:
```python
from PIL import Image
# 读取图片
img = Image.open('image.jpg')
```
接着,我们可以使用Pillow库中的ImageDraw模块,绘制曲线并获取曲线上的坐标点:
```python
from PIL import Image, ImageDraw
# 读取图片
img = Image.open('image.jpg')
# 创建绘图对象
draw = ImageDraw.Draw(img)
# 绘制曲线
draw.line([(100, 100), (200, 200), (300, 150)], fill='red', width=2)
# 获取曲线上的坐标点
points = []
for x in range(100, 301):
y = int((x - 100) * (200 - 100) / (200 - 100) + 100)
points.append((x, y))
```
最后,我们可以使用openpyxl库将坐标点写入Excel表格:
```python
from PIL import Image, ImageDraw
from openpyxl import Workbook
# 读取图片
img = Image.open('image.jpg')
# 创建绘图对象
draw = ImageDraw.Draw(img)
# 绘制曲线
draw.line([(100, 100), (200, 200), (300, 150)], fill='red', width=2)
# 获取曲线上的坐标点
points = []
for x in range(100, 301):
y = int((x - 100) * (200 - 100) / (200 - 100) + 100)
points.append((x, y))
# 写入Excel表格
wb = Workbook()
ws = wb.active
ws.append(['x', 'y'])
for point in points:
ws.append(point)
wb.save('points.xlsx')
```
这样,我们就可以将曲线上的坐标点提取并写入Excel表格了。
阅读全文
相关推荐











