0

我正在尝试使用 mplot3d 模块在 3d 中绘制 2D 曲面图。

我知道如何“手动”找到最大值及其位置(就行和列而言),这对我正在做的事情非常重要。有没有办法将这些信息绘制到峰值上?也就是说,在峰值旁边写 (maxval,row,col) ?

PS当我问这个时。也许有一种简单的方法可以识别第二个峰值(或任何其他峰值?)。我目前正在使用掩码,以掩盖第一个峰并找到第二个峰,但我必须非常小心选择边,因为如果我碰巧掩码太少,一些非峰的东西会被识别出来作为一个峰值,将无法识别真正的第二个峰值,从而扰乱了称为“峰峰值”信噪比的测量。

在此处输入图像描述 曲面图

我目前使用的代码是:

frame_a = gdal.Open( "frame_{0:05d}.tif".format(274) ).ReadAsArray()
# in case this helps, this is how the images are read, they are 16-bit GS tiffs.    
frame_b = gdal.Open( "frame_{0:05d}.tif".format(287) ).ReadAsArray()


#this does some clever stuff but basically it returns a 2-D 32x32 array.
corr = correlate_windows( windows_a[99], windows_b[99], corr_method = corr_method, nfftx=nfftx, nffty=nffty )

#this is how I find the position of max value.
column = np.argmax(np.max(corr, axis=0))
row = np.argmax(np.max(corr, axis=1))
maximum = corr.max()
print 'column = ' + str(column)
print 'row = ' +str(row)
print 'peak_1 = ' + str(maximum)



import matplotlib.cm as cmps
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import LinearLocator, FormatStrFormatter

fig = pl.figure()

ax = Axes3D(fig)

# window size is 32 in this case

nx, ny = window_size*2, window_size*2

xx = range(nx)

yy = range(ny)

X, Y = np.meshgrid(xx, yy)

ax.plot_surface(X , Y , corr , rstride = 1, cstride = 1 )

pl.show()
4

1 回答 1

0

关于您的第二个问题,您可能会发现以下帖子很有用

Python/SciPy 的寻峰算法

在我所做的一些工作中,我们使用了一个简单的导数近似值,当这个变化表明你有一个峰值(在一维数据中),然后可以添加一些参数来消除由于噪声引起的峰值。要将其扩展到 2D,我已经阅读了有关遵循梯度(向上或向下)直到达到最大值的算法。这些可能相当棘手,因为很容易陷入局部最小值/最大值。如果您对此进行跟进,请在此处链接,因为我想看看人们想出什么。

于 2013-06-26T16:02:12.600 回答