python - 如何使用python获取图像中每个点(像素)的高程
问题描述
我正在尝试使用 python 的图像处理来获取图像中每个像素的高度。我的第一次尝试是通过使用以下代码将图像转换为灰度并将 2d 图像转换为 3d 图像:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import imread
imageFile = 'D:\Books\Pav Man\PICS\pic (17) - Copy.png'
mat = imread(imageFile)
mat = mat[:,:,0] # get the first channel
#mat = mat - np.full_like(mat , mat.mean()) #Use this to get negative value
rows, cols = mat.shape
xv, yv = np.meshgrid(range(cols), range(rows)[::-1])
blurred = ndimage.gaussian_filter(mat, sigma=(5, 5), order=0)
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(221)
ax.imshow(mat, cmap='gray')
ax = fig.add_subplot(222, projection='3d')
ax.elev= 75
ax.plot_surface(xv, yv, mat)
ax = fig.add_subplot(223)
ax.imshow(blurred, cmap='gray')
ax = fig.add_subplot(224, projection='3d')
ax.elev= 75
ax.plot_surface(xv, yv, blurred)
plt.show()
垫子包含每个像素的 x,y,z 值,x = 宽度坐标,y = 高度坐标,z = 灰度值,范围从 0 到 1,但不包括实际高程。
第二次尝试是使用以下链接中提到的 2 个图像的深度数据: https ://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html
但是没有明确的方法来估计或预测图像中点的高程。下图描述了我的意思:
我的问题是如何获取图像中每个点的高程以创建地形剖面?
解决方案
推荐阅读
- ubuntu - 安装 dart-sdk 后找不到 pub 命令
- javascript - 如何在 lerna exec 中设置范围标志?
- android - 在 GridLayoutView 中获取项目宽度
- python - Flask & mod_wsgi post请求执行get函数
- java - Box 中的 Java Swing 组件不可点击
- kotlin - Kotlin 方差问题
- python - 如何将'cluster'和'pylab'导入Pycharm
- wordpress - Wordpress 表单发送
- java - 想将 BufferedImage 保存为 jpg 但我的代码将其保存为文本文件
- xamarin.android - Xamarin.Android 上的 Release 版本中缺少 Assembly*Attributes