findpeaks用于检测一维矢量和二维阵列(图像)中的峰值和谷值。
findpeaks的Python项目详细描述
查找峰值
这个库findpeaks
旨在检测一维向量和二维阵列(图像)中的峰值,而不需要对峰值形状或基线噪声做任何假设。为了确保在全局和局部高度以及在噪声数据中能够检测到峰值,采用了多种预处理和去噪方法。在
导航到API documentations以获取更详细和结构化的信息。在
内容
安装
- 从PyPI安装findpeaks(推荐)。findpeaks与python3.6+兼容,可在Linux、macosx和Windows上运行。在
- 可以按如下方式创建新环境:
pip install findpeaks
导入findpeaks包
^{pr2}$示例1:1D矢量低分辨率
# Load libraryfromfindpeaksimportfindpeaks# DataX=[9,60,377,985,1153,672,501,1068,1110,574,135,23,3,47,252,812,1182,741,263,33]# Initializefp=findpeaks(lookahead=1)results=fp.fit(X)# Plotfp.plot()
^{1}$ 在
# Initialize with interpolation parameterfp=findpeaks(lookahead=1,interpolate=10)results=fp.fit(X)fp.plot()
在
示例2:1D矢量低分辨率
# Load libraryfromfindpeaksimportfindpeaks# DataX=[10,11,9,23,21,11,45,20,11,12]# Initializefp=findpeaks(method='peakdetect',lookahead=1)results=fp.fit(X)# Plotfp.plot()fp=findpeaks(method='topology',lookahead=1)results=fp.fit(X)fp.plot()fp.plot_persistence()
在
# Initialize with interpolate parameterfp=findpeaks(method='peakdetect',lookahead=1,interpolate=10)results=fp.fit(X)fp.plot()fp=findpeaks(method='topology',lookahead=1,interpolate=10)results=fp.fit(X)fp.plot()
在
示例3:1D矢量高分辨率# Load libraryimportnumpyasnpfromfindpeaksimportfindpeaks# Datai=10000xs=np.linspace(0,3.7*np.pi,i)X=(0.3*np.sin(xs)+np.sin(1.3*xs)+0.9*np.sin(4.2*xs)+0.06*np.random.randn(i))# Initializefp=findpeaks(method='peakdetect')results=fp.fit(X)# Plotfp.plot1d()fp=findpeaks(method='topology',limit=1)results=fp.fit(X)fp.plot1d()fp.plot_persistence()
在
示例4:使用默认设置的二维数组(图像)
# Import libraryfromfindpeaksimportfindpeaks# Import exampleX=fp.import_example()print(X)array([[0.,0.,0.,0.,0.,0.,0.,0.,0.4,0.4],[0.,0.,0.,0.,0.,0.,0.7,1.4,2.2,1.8],[0.,0.,0.,0.,0.,1.1,4.,6.5,4.3,1.8],[0.,0.,0.,0.,0.,1.4,6.1,7.2,3.2,0.7],[...,...,...,...,...,...,...,...,...,...],[0.,0.4,2.9,7.9,5.4,1.4,0.7,0.4,1.1,1.8],[0.,0.,1.8,5.4,3.2,1.8,4.3,3.6,2.9,6.1],[0.,0.,0.4,0.7,0.7,2.5,9.,7.9,3.6,7.9],[0.,0.,0.,0.,0.,1.1,4.7,4.,1.4,2.9],[0.,0.,0.,0.,0.,0.4,0.7,0.7,0.4,0.4]])# Initializefp=findpeaks(method='mask')# Fitfp.fit(X)# Plot the pre-processing stepsfp.plot_preprocessing()# Plot allfp.plot()# Initializefp=findpeaks(method='topology')# Fitfp.fit(X)
输入数字
在
掩蔽方法检测正确的峰值。在
fp.plot()
在
从二维到三维网格图的转换看起来非常好。但由于输入数据的分辨率较低,因此存在粗糙表面。在
fp.plot_mesh()
在
持久性图似乎检测到了正确的峰值。在
fp.plot_persistence()
^{15}$ 在
例5:具有预处理步骤的2D数组(图像)
# Import libraryfromfindpeaksimportfindpeaks# Import exampleX=fp.import_example()# Initializefp=findpeaks(method='topology',scale=True,denoise=10,togray=True,imsize=(50,100),verbose=3)# Fitresults=fp.fit(X)# Plot allfp.plot()
显示绘图:
fp.plot_preprocessing()
^{图18}$ 在
由于预处理步骤中包含一些加权平滑,因此掩模效果并不理想。在
fp.plot()
在
由于预处理步骤产生了一定的平滑度,因此网格图具有较高的分辨率。在
fp.plot_mesh()
在
持久性图确实显示了正确峰值的检测。在
fp.plot_persistence()
在
去噪实例
fromfindpeaksimportfindpeaksfp=findpeaks()img=fp.import_example('2dpeaks_image')importfindpeaks# filters parameters# window sizewinsize=15# damping factor for frostk_value1=2.0# damping factor for lee enhancedk_value2=1.0# coefficient of variation of noisecu_value=0.25# coefficient of variation for lee enhanced of noisecu_lee_enhanced=0.523# max coefficient of variation for lee enhancedcmax_value=1.73# Some pre-processing# Resizeimg=findpeaks.stats.resize(img,size=(300,300))# Make grey imageimg=findpeaks.stats.togray(img)# Scale between [0-255]img=findpeaks.stats.scale(img)# Denoising# fastnlimg_fastnl=findpeaks.stats.denoise(img.copy(),method='fastnl',window=winsize)# bilateralimg_bilateral=findpeaks.stats.denoise(img.copy(),method='bilateral',window=winsize)# frost filterimage_frost=findpeaks.frost_filter(img.copy(),damping_factor=k_value1,win_size=winsize)# kuan filterimage_kuan=findpeaks.kuan_filter(img.copy(),win_size=winsize,cu=cu_value)# lee filterimage_lee=findpeaks.lee_filter(img.copy(),win_size=winsize,cu=cu_value)# lee enhanced filterimage_lee_enhanced=findpeaks.lee_enhanced_filter(img.copy(),win_size=winsize,k=k_value2,cu=cu_lee_enhanced,cmax=cmax_value)# mean filterimage_mean=findpeaks.mean_filter(img.copy(),win_size=winsize)# median filterimage_median=findpeaks.median_filter(img.copy(),win_size=winsize)
策划
importmatplotlib.pyplotaspltplt.figure();plt.imshow(img_fastnl,cmap='gray');plt.title('Fastnl');plt.grid(False)plt.figure();plt.imshow(img_bilateral,cmap='gray');plt.title('Bilateral')plt.figure();plt.imshow(image_frost,cmap='gray');plt.title('Frost')plt.figure();plt.imshow(image_kuan,cmap='gray');plt.title('Kuan')plt.figure();plt.imshow(image_lee,cmap='gray');plt.title('Lee')plt.figure();plt.imshow(image_lee_enhanced,cmap='gray');plt.title('Lee Enhanced')plt.figure();plt.imshow(image_mean,cmap='gray');plt.title('Mean')plt.figure();plt.imshow(image_median,cmap='gray');plt.title('Median')
找出去噪图像的峰值
fromfindpeaksimportfindpeaksfp=findpeaks(scale=False,denoise=None,togray=False,imsize=False,verbose=3)fp.fit(image_lee_enhanced)fp.plot_persistence()fp.plot_mesh(wireframe=False,title='image_lee_enhanced')
引文
如果这对你的研究有用,请在你的出版物中引用findpeaks。以下是BibTeX条目示例:
@misc{erdogant2020findpeaks,title={findpeaks},author={Erdogan Taskesen},year={2020},howpublished={\url{https://github.com/erdogant/findpeaks}},}
参考文献
- https://github.com/erdogant/findpeaks
- https://github.com/Anaxilaus/peakdetect
- https://www.sthu.org/blog/13-perstopology-peakdetection/index.html
维护人员
^{pr21}$
标签:
- 项目
标签: