区分轴上的像素大小

2024-10-06 16:23:09 发布

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

我有一张1000x1350像素的图像。这与实际深度和距离(8844m x 10000m)有关。我已经在图像中绘制了一个500x500米的网格,而这个网格表示一个500x500米的网格,特别是x轴和y轴反映像素的简单比率

我一整天都在讨论这个问题,已经在这里写了一个关于堆栈溢出的糟糕问题,但我相信我找到了正确的问题:

有没有办法给每个像素一个值来代表我的真实距离,同时保持相同的实际像素尺寸

谢谢


Tags: 图像网格距离堆栈尺寸绘制代表像素
1条回答
网友
1楼 · 发布于 2024-10-06 16:23:09

使用imshow()中的extent=参数来定义图像的数据坐标

From the docs

extent : scalars (left, right, bottom, top), optional, default: None

The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.

plt.imshow(img, extent=(0,8844,0,10000))
plt.xlabel('depth (m)')
plt.ylabel('distance (m)')

enter image description here

栅格取决于轴的间距。如果需要500x500m的栅格,则必须调整轴间距,然后启用栅格

plt.xticks(np.arange(0,8844,500));
plt.yticks(np.arange(0,10000,500));
plt.grid(True)

enter image description here

相关问题 更多 >