繁体   English   中英

matplotlib plot_surface 3D 深度值

[英]matplotlib plot_surface 3D depth values

我使用以下代码获取显示的 2 个图像的 3D 深度投影。 我需要最大和最小深度值,以及这些最大和最小深度值的 x 和 y 坐标。 是否有我可以从中获取此信息的功能/方法? 即使它将使用 matplotlib 以外的库。

import cv2
import numpy as np
import  math
import scipy.ndimage as ndimage

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


image2=cv2.imread('D:/Post_Grad/STDF/iPython_notebooks/2228.jpg')
image2 = image2[:,:,1] # get the first channel
rows, cols = image2.shape
x, y= np.meshgrid(range(cols), range(rows)[::-1])

blurred = ndimage.gaussian_filter(image2,(5, 5))
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(221)
ax.imshow(image2, cmap='gray')
ax = fig.add_subplot(222, projection='3d')
ax.elev= 5
f1=ax.plot_surface(x,y,image2, cmap=cm.jet)
ax = fig.add_subplot(223)
ax.imshow(blurred, cmap='gray')
ax = fig.add_subplot(224, projection='3d')
ax.elev= 5
f2=ax.plot_surface(x,y,blurred, cmap=cm.jet)
plt.show()

在此处输入图像描述

最大深度和最小深度只是图像的最大和最小像素值。 您可以通过 np.max(image2)、np.min(image2) 等轻松找到值。也可以通过简单的 function 找到坐标

def getCoord(image,val):
    coords = []
    for i in range(image.shape[0]):
        for j in range(image.shape[1]):
            if image[i][j] == val:
                coords.append([i,j])
    return coords

所以 getCoord(image2,np.max(image2)) 将返回 image2 中的所有最高像素坐标(它可以大于 1),getCoord(blurred,np.min(blurred)) 将返回 blurred 等中的所有最低像素坐标。 .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM