Skip to content

Commit

Permalink
bug fix in detection of peaks when using 2d images
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Oct 25, 2023
1 parent 2d12f51 commit 67eadb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions findpeaks/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
# pip install opencv-python
# import matplotlib.pyplot as plt
# from findpeaks import findpeaks
# %% Issue

from findpeaks import findpeaks
import os
import cv2
path = r'https://user-images.githubusercontent.com/12035402/274193739-cdfd8986-91eb-4211-bef6-ebad041f47ae.png'
# path=r'tmp_peak.PNG.png'
fp = findpeaks(method='topology', denoise='lee_enhanced', params={'window':5}, whitelist='peak', limit=20)
X = fp.imread(path)
results = fp.fit(X)

result_df = results['persistence']
peak = result_df.index[result_df['peak']==True].tolist()
print(result_df.loc[peak])
fp.plot_persistence()
fp.plot(figsize=(35, 16))
fp.plot_mesh(view=(90, 90))


# %%
from findpeaks import findpeaks
Expand Down
4 changes: 3 additions & 1 deletion findpeaks/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _get_comp_birth(p):
ni = [uf[q] for q in _iter_neighbors(p, w, h) if q in uf]
nc = sorted([(_get_comp_birth(q), q) for q in set(ni)], reverse=True)

if i == 0: groups0[p] = (v, v, None)
# if i == 0: groups0[p] = (v, v, None)
uf.add(p, -i)

if len(nc) > 0:
Expand All @@ -451,6 +451,8 @@ def _get_comp_birth(p):
if uf[q] not in groups0:
groups0[uf[q]] = (float(bl), float(bl) - float(v), p)
uf.union(oldp, q)
elif groups0.get(p, None) is None:
groups0[p] = (v, v, p)

groups0 = [(k, groups0[k][0], groups0[k][1], groups0[k][2]) for k in groups0]
groups0.sort(key=lambda g: g[2], reverse=True)
Expand Down

0 comments on commit 67eadb7

Please sign in to comment.