-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_intensity_binary_mask.py
47 lines (36 loc) · 1.43 KB
/
create_intensity_binary_mask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
def create_intensity_binary_mask(gammatonegram, intensity_threshold):
"""
Creates an Intensity Binary Mask from the gammatonegram for a given intensity level threshold.
Args:
gammatonegram (ndarray): The input gammatonegram.
Returns:
ndarray: The resulting intensity binary mask.
"""
n_bins, n_frames = gammatonegram.shape
intensity_binary_mask = np.zeros((n_bins, n_frames))
for i in range(n_bins):
for j in range(n_frames):
if gammatonegram[i, j] >= intensity_threshold:
intensity_binary_mask[i, j] = 1
else:
intensity_binary_mask[i, j] = 0
return intensity_binary_mask
def create_intensity_binary_mask_nan(gammatonegram):
"""
Creates an Intensity Binary Mask with NaN values from the gammatonegram for a given intensity level threshold.
Args:
gammatonegram (np.ndarray): The input matrix.
intensity_threshold (int): The intensity level threshold.
Returns:
np.ndarray: The intensity binary mask with NaN values.
"""
intensity_binary_mask = np.zeros_like(gammatonegram)
n_bins, n_frames = gammatonegram.shape
for i in range(n_bins):
for j in range(n_frames):
if gammatonegram[i, j] >= 1:
intensity_binary_mask[i, j] = 1
else:
intensity_binary_mask[i, j] = np.nan
return intensity_binary_mask