opencv-python:将2D灰度图像转换成3D图像

import numpy as np
import cv2
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 读取灰度图像
img_path = "C:/Users/z/Desktop/image/1.png"  # 替换为你的图像文件路径
gray_img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)

# 获取图像的高度和宽度
height, width = gray_img.shape

# 创建X和Y坐标网格
x = np.arange(0, width, 1)
y = np.arange(0, height, 1)
x, y = np.meshgrid(x, y)

# 将灰度值作为Z轴的高度
z = gray_img

# 创建三维图像
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 绘制表面图
surf = ax.plot_surface(x, y, z, cmap='gray')  # 使用灰度颜色映射

# 设置坐标轴的标签
ax.set_xlabel('X Coordinate')
ax.set_ylabel('Y Coordinate')
ax.set_zlabel('Intensity')

# 添加右侧的色卡条
fig.colorbar(surf, shrink=0.5, aspect=5)

# 显示图像
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值