Skip to content

Commit

Permalink
len male upravy
Browse files Browse the repository at this point in the history
  • Loading branch information
MarketaJu committed Sep 7, 2020
1 parent e837bfb commit cb06828
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
24 changes: 7 additions & 17 deletions accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,12 @@ def insert(self, l, weight=None):
self.accumulate_subspaces(D, D_I, A, A_I)


def find_peaks_in_subspace(self, subspace, t=0.8, prominence=2, min_dist=1):
def find_peaks_in_subspace(self, subspace, t_abs, prominence, min_dist):
"""
Retrieve locations with prominent local maxima from one part of the accumulator
"""
de = dilation(subspace + 1, ) / erosion(subspace + 1)
p = peak_local_max(subspace, threshold_rel=t, min_distance=min_dist, exclude_border=False)
#print(p)
p = peak_local_max(subspace, threshold_abs=t_abs, min_distance=min_dist, exclude_border=False)
r,c = p[:,0], p[:,1]
v = subspace[r,c]
valid = de[r,c] > prominence
Expand All @@ -336,7 +335,6 @@ def find_peaks_in_subspace(self, subspace, t=0.8, prominence=2, min_dist=1):
peaks[i,1] = np.sum(neighborhood * weight_r).astype(float)
peaks[i,0] = np.sum(neighborhood * weight_c).astype(float)

print(peaks)
return peaks,values


Expand All @@ -348,26 +346,18 @@ def find_peaks(self, t=0.8, prominence=2, min_dist=1):
peaks_ds = []
values = []

threshold_abs = np.max(self.A) * t

for i, (s, f) in enumerate(zip(self.A, space_flip)):
p,v = self.find_peaks_in_subspace(s, t, prominence, min_dist)
p,v = self.find_peaks_in_subspace(s, threshold_abs, prominence, min_dist)

p_i = self.points_inverse(p*f/scale)
p_ds = p*f/scale
p_i = self.points_inverse(p_ds)

peaks.append(p_i)
values.append(v)
peaks_ds.append(p*f)

#p,v = self.find_peaks_in_subspace(self.A[2], t, prominence, min_dist)

#p_i = self.points_inverse(p*space_flip[2]/scale)

#peaks.append(p_i)
#values.append(v)
#peaks_ds.append(p*space_flip[2])

#print(p)
#print(p*space_flip[2])

return np.vstack(peaks), np.hstack(values), np.vstack(peaks_ds)

def attach_spaces(self):
Expand Down
Binary file modified chess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@

A = DS.attach_spaces()
_,ax = plt.subplots(1, figsize=(5,5))
ax.imshow(A, cmap="inferno", extent = (-d+0.5/scale,d-0.5/scale,d-0.5/scale,-d+0.5/scale))
ax.set(title="Accumulator", xticks=np.linspace(-d+1,d-1,5), yticks=np.linspace(-d+1,d-1,5))
ax.plot(p_ds[:,0]/scale, p_ds[:,1]/scale, "r+")
ax.imshow(A, cmap="inferno", extent = (-DS.size+0.5,DS.size-0.5,DS.size-0.5,-DS.size+0.5)/scale)
ax.set(title="Accumulator", xticks=np.linspace(-DS.size+1,DS.size-1,5)/scale, yticks=np.linspace(-DS.size+1,DS.size-1,5)/scale)
ax.plot(p_ds[:,0], p_ds[:,1], "r+")

ax.invert_yaxis()
plt.tight_layout()
Expand Down

0 comments on commit cb06828

Please sign in to comment.