Merge pull request #135 from anuragkumarak95/master

Update fingerprint.py
This commit is contained in:
Will Drevo 2019-05-27 00:21:16 -07:00 committed by GitHub
commit 999c66a24e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,9 +56,9 @@ MAX_HASH_TIME_DELTA = 200
PEAK_SORT = True PEAK_SORT = True
###################################################################### ######################################################################
# Number of bits to throw away from the front of the SHA1 hash in the # Number of bits to grab from the front of the SHA1 hash in the
# fingerprint calculation. The more you throw away, the less storage, but # fingerprint calculation. The more you grab, the more memory storage,
# potentially higher collisions and misclassifications when identifying songs. # with potentially lesser collisions of matches.
FINGERPRINT_REDUCTION = 20 FINGERPRINT_REDUCTION = 20
def fingerprint(channel_samples, Fs=DEFAULT_FS, def fingerprint(channel_samples, Fs=DEFAULT_FS,
@ -94,7 +94,7 @@ def get_2D_peaks(arr2D, plot=False, amp_min=DEFAULT_AMP_MIN):
struct = generate_binary_structure(2, 1) struct = generate_binary_structure(2, 1)
neighborhood = iterate_structure(struct, PEAK_NEIGHBORHOOD_SIZE) neighborhood = iterate_structure(struct, PEAK_NEIGHBORHOOD_SIZE)
# find local maxima using our fliter shape # find local maxima using our filter shape
local_max = maximum_filter(arr2D, footprint=neighborhood) == arr2D local_max = maximum_filter(arr2D, footprint=neighborhood) == arr2D
background = (arr2D == 0) background = (arr2D == 0)
eroded_background = binary_erosion(background, structure=neighborhood, eroded_background = binary_erosion(background, structure=neighborhood,
@ -110,11 +110,13 @@ def get_2D_peaks(arr2D, plot=False, amp_min=DEFAULT_AMP_MIN):
# filter peaks # filter peaks
amps = amps.flatten() amps = amps.flatten()
peaks = zip(i, j, amps) peaks = zip(i, j, amps)
peaks_filtered = [x for x in peaks if x[2] > amp_min] # freq, time, amp peaks_filtered = filter(lambda x: x[2]>amp_min, peaks) # freq, time, amp
# get indices for frequency and time # get indices for frequency and time
frequency_idx = [x[1] for x in peaks_filtered] frequency_idx = []
time_idx = [x[0] for x in peaks_filtered] time_idx = []
for x in peaks_filtered:
frequency_idx.append(x[1])
time_idx.append(x[0])
if plot: if plot:
# scatter of the peaks # scatter of the peaks