Skip to content

Commit 6a5a95e

Browse files
Added new mask and masked output image
1 parent 570a97d commit 6a5a95e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

batbot/spectrogram/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,8 @@ def compute_wrapper(
18231823

18241824
output_paths = []
18251825
compressed_paths = []
1826+
mask_paths = []
1827+
masked_paths = []
18261828
if not fast_mode:
18271829
datas = [
18281830
(output_paths, 'jpg', stft_db),
@@ -1834,6 +1836,24 @@ def compute_wrapper(
18341836
(compressed_paths, 'compressed.jpg', segments['stft_db']),
18351837
]
18361838

1839+
# Create masked image
1840+
weights = segments['costs'].copy()
1841+
weights[weights < weights.mean()] = 0
1842+
weights[weights > 0] = weights.max()
1843+
weights = weights.astype(np.float32)
1844+
kernel = 11
1845+
weights = cv2.GaussianBlur(
1846+
weights, (kernel, kernel), sigmaX=4, sigmaY=4, borderType=cv2.BORDER_DEFAULT
1847+
)
1848+
weights /= weights.max()
1849+
masked = segments['stft_db'] * weights
1850+
masked = normalize_stft(masked, None, np.uint8)
1851+
1852+
datas += [
1853+
(mask_paths, 'mask.jpg', segments['costs']),
1854+
(masked_paths, 'masked.jpg', masked),
1855+
]
1856+
18371857
for accumulator, tag, data in datas:
18381858
if data.dtype != np.uint8:
18391859
data_ = data.astype(np.float32)
@@ -1863,6 +1883,8 @@ def compute_wrapper(
18631883
'spectrogram': {
18641884
'uncompressed.path': output_paths,
18651885
'compressed.path': compressed_paths,
1886+
'mask.path': mask_paths,
1887+
'masked.path': masked_paths,
18661888
},
18671889
'global_threshold.amp': int(round(255.0 * (global_threshold / max_value))),
18681890
'sr.hz': int(sr),
@@ -1886,6 +1908,8 @@ def compute_wrapper(
18861908
'width.px': segments['stft_db'].shape[1],
18871909
'height.px': segments['stft_db'].shape[0],
18881910
}
1911+
metadata['size']['mask'] = metadata['size']['compressed']
1912+
metadata['size']['masked'] = metadata['size']['compressed']
18891913

18901914
metadata_path = f'{out_file_stem}.metadata.json'
18911915
with open(metadata_path, 'w') as metafile:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ python_requires = >=3.7
3838

3939
[options.entry_points]
4040
console_scripts =
41-
batbot = batbot.batbot:cli
41+
batbot = batbot.batbot_cli:cli
4242

4343
[tool:pytest]
4444
minversion = 5.4

0 commit comments

Comments
 (0)