maad.features.centroid_features

maad.features.centroid_features(Sxx, rois=None, im_rois=None)[source]

Computes intensity centroid of a spectrogram. If regions of interest rois are provided, the centroid is computed for each region.

Parameters:
Sxx2D array

Spectrogram

rois: pandas DataFrame, default is None

Regions of interest where descriptors will be computed. Array must have a valid input format with column names: min_t, min_f, max_t, and max_f. Use the function maad.util.format_features before using centroid_features to format of the rois DataFrame correctly.

im_rois: 2d ndarray

image with labels as values

Returns:
centroid: pandas DataFrame

Centroid of each region of interest.

Examples

>>> import maad

Get centroid from the whole power spectrogram

>>> from maad.sound import load, spectrogram
>>> from maad.features import centroid_features
>>> from maad.util import (power2dB, format_features, overlay_rois, plot2d, overlay_centroid)

Load audio and compute spectrogram

>>> s, fs = load('../data/spinetail.wav') 
>>> Sxx,tn,fn,ext = spectrogram(s, fs, db_range=80) 
>>> Sxx = power2dB(Sxx, db_range=80)

Load annotations and plot

>>> from maad.util import read_audacity_annot
>>> rois = read_audacity_annot('../data/spinetail.txt') 
>>> rois = format_features(rois, tn, fn) 
>>> ax, fig = plot2d (Sxx, extent=ext)
>>> ax, fig = overlay_rois(Sxx,rois, extent=ext, ax=ax, fig=fig)

Compute the centroid of each rois, format to get results in the temporal and spectral domain and overlay the centroids.

>>> centroid = centroid_features(Sxx, rois) 
>>> centroid = format_features(centroid, tn, fn)
>>> ax, fig = overlay_centroid(Sxx,centroid, extent=ext, ax=ax, fig=fig)