Exemplo n.º 1
0
                                    })

# Then we create a mask (i.e. binarization of the spectrogram) by using the
# double thresholding technique
im_mask = rois.create_mask(im=Sxx_db_noNoise_smooth,
                           mode_bin='relative',
                           bin_std=8,
                           bin_per=0.5,
                           verbose=False,
                           display=False)

# Finaly, we put together pixels that belong to the same acoustic event, and
# remove very small events (<=25 pixel²)
im_rois, df_rois = rois.select_rois(im_mask,
                                    min_roi=25,
                                    max_roi=None,
                                    display=True,
                                    **{'extent': ext})

# format dataframe df_rois in order to convert pixels into time and frequency
df_rois = format_features(df_rois, tn, fn)

# overlay bounding box on the original spectrogram
ax0, fig0 = rois.overlay_rois(Sxx_db, df_rois, **{
    'vmin': 0,
    'vmax': dB_max,
    'extent': ext
})

# Compute and visualize centroids
df_centroid = features.centroid_features(Sxx_db, df_rois, im_rois)
Exemplo n.º 2
0
Sxx, tn, fn, ext = sound.spectrogram(s_filt, fs, nperseg=1024, noverlap=512)
Sxx_db = power2dB(Sxx, db_range=db_max) + db_max
plot2d(Sxx_db, **{'extent': ext})

#%%
# 1. Find regions of interest
# ---------------------------
# To find regions of interest in the spectrogram, we will remove stationary background noise and then find isolated sounds using a double threshold method. Small ROIs due to noise in the signal will be removed.

Sxx_db_rmbg, _, _ = sound.remove_background(Sxx_db)
Sxx_db_smooth = sound.smooth(Sxx_db_rmbg, std=1.2)
im_mask = rois.create_mask(im=Sxx_db_smooth,
                           mode_bin='relative',
                           bin_std=2,
                           bin_per=0.25)
im_rois, df_rois = rois.select_rois(im_mask, min_roi=50, max_roi=None)

# Format ROIs and visualize the bounding box on the audio spectrogram.
df_rois = format_features(df_rois, tn, fn)
ax0, fig0 = overlay_rois(Sxx_db, df_rois, **{
    'vmin': 0,
    'vmax': 60,
    'extent': ext
})

#%%
# 2. Compute acoustic features
# ----------------------------
# The ``shape_feaures`` function uses bidimensional wavelets to get the texture and spectro-temporal shape coeficients of each ROI. Wavelets have the advantage of being robust when the signal-to-noise ratio is low, and derive homogeneous descriptors which facilitate the clustering process. The wavelet decomposition is performed on the complete spectrogram, hence the coeficients for ROIs do not vary much even when not the time-frequency bounds are not exact. The centroid features gives an estimate of the median frequency of the ROIs.

df_shape, params = features.shape_features(Sxx_db,
                           fig=fig,
                           ax=ax)

###=============== find ROI 2D =================
# create a mask
X = linear_scale(Sxx)
im_mask = create_mask(im=X,
                      ext=ext,
                      mode_bin='relative',
                      bin_std=1.5,
                      bin_per=0.1,
                      display=False)
# create rois from mask
im_rois, rois = select_rois(im_mask,
                            min_roi=200,
                            max_roi=im_mask.shape[1] * 5,
                            ext=ext,
                            display=False)
rois = format_features(rois, tn, fn)

# view bbox
ax, fig = overlay_rois(Sxx, ext, rois, vmin=-120, vmax=20)

# Compute and visualize features
shape, params = shape_features(Sxx, resolution='low', rois=rois)
plot_shape(shape.mean(), params)

# Compute and visualize centroids from rectangular rois
centroid = centroid_features(Sxx, rois=rois)
centroid = format_features(centroid, tn, fn)
overlay_centroid(Sxx,
# Then we create a mask (i.e. binarization of the spectrogram) by using the
# double thresholding technique
im_mask = rois.create_mask(im=Sxx_db_noNoise_smooth,
                           ext=ext,
                           mode_bin='relative',
                           bin_std=6,
                           bin_per=0.5,
                           verbose=False,
                           display=False)

# Finaly, we put together pixels that belong to the same acoustic event, and
# remove very small events (<=25 pixel²)
im_rois, df_rois = rois.select_rois(im_mask,
                                    min_roi=25,
                                    max_roi=None,
                                    ext=ext,
                                    display=False,
                                    figsize=(4, (t1 - t0)))

# format dataframe df_rois in order to convert pixels into time and frequency
df_rois = format_features(df_rois, tn, fn)

# overlay bounding box on the original spectrogram
ax, fig = rois.overlay_rois(Sxx_db, ext, df_rois, vmin=0, vmax=96)

# Compute and visualize centroids
df_centroid = features.centroid_features(Sxx_db, df_rois, im_rois)
df_centroid = format_features(df_centroid, tn, fn)
ax, fig = features.overlay_centroid(Sxx_db,
                                    ext,
                                    df_centroid,