特定の配列から極大値を検出しようとしています。配列は、ハフ ライン変換を計算した後に得られる正弦曲線です。画像はこちら
これが numpy ファイルaccumulator.npyです。明らかに、2 つの極大値があります。これら2つの最大値を検出する最良の方法は何だろうと思っていました. また、最大値を見つけた後に線をプロットするにはどうすればよいですか? ありがとう。
特定の配列から極大値を検出しようとしています。配列は、ハフ ライン変換を計算した後に得られる正弦曲線です。画像はこちら
これが numpy ファイルaccumulator.npyです。明らかに、2 つの極大値があります。これら2つの最大値を検出する最良の方法は何だろうと思っていました. また、最大値を見つけた後に線をプロットするにはどうすればよいですか? ありがとう。
スキーイメージ関数を使用peak_local_max()
してピークを見つけることができます。あなたが期待しているように見える以上のものがあるので、試してみるためにいくつかのガウス平滑化を追加しました.
最後に、データを 3D で視覚化するためのプロットもありますが、無視してかまいません。
#!/usr/bin/env python3
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
from skimage.feature import peak_local_max
from skimage import img_as_float
# Load data and find maxima
data = np.load('accum.npy')
im = img_as_float(data)
image_max = ndi.maximum_filter(im, size=20, mode='constant')
# Experiment with various smoothing parameters
for sigma in range(4):
coordinates = peak_local_max(ndi.gaussian_filter(im,sigma=sigma), min_distance=20)
print(f"Sigma for smoothing: {sigma}, coordinates of peaks:")
print(coordinates)
# Plotting stuff
sigmaForPlot=0
fig = plt.figure()
ax = plt.axes(projection='3d')
x = np.outer(np.ones(800),np.arange(300))
y = np.outer(np.arange(800), np.ones(300))
ax.plot_surface(x, y,ndi.gaussian_filter(im,sigma=sigmaForPlot),cmap='viridis', edgecolor='none')
ax.set_title('Surface plot')
plt.show()
サンプル出力
Sigma for smoothing: 1, coordinates of peaks:
[[595 113]
[589 36]
[448 80]
[400 144]
[351 260]
[251 166]
[210 216]]
Sigma for smoothing: 2, coordinates of peaks:
[[589 36]
[399 144]
[239 170]
[210 216]]
Sigma for smoothing: 3, coordinates of peaks:
[[589 36]
[398 145]
[210 216]]