librosa.segment.structure_feature¶
-
librosa.segment.
structure_feature
(rec, pad=True, inverse=False)[source]¶ Compute the structure feature from a recurrence matrix.
The i’th column of the recurrence matrix is shifted up by i. The resulting matrix is indexed horizontally by time, and vertically by lag.
Warning
Deprected in librosa 0.4 Functionality is superseded by
librosa.segment.recurrence_to_lag
andlibrosa.segment.lag_to_recurrence
.Parameters: rec : np.ndarray [shape=(t,t) or shape=(2*t, t)]
recurrence matrix or pre-computed structure feature
pad : bool [scalar]
Pad the matrix with t rows of zeros to avoid looping.
inverse : bool [scalar]
Unroll the opposite direction. This is useful for converting structure features back into recurrence plots.
Returns: struct : np.ndarray [shape=(2*t, t) or shape=(t, t)]
struct[i, t] = the recurrence at time t with lag i.
Note
negative lag values are supported by wrapping to the end of the array.
See also
recurrence_matrix
- build a recurrence matrix from feature vectors
Examples
Build the structure feature over mfcc similarity
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> mfccs = librosa.feature.mfcc(y=y, sr=sr) >>> recurrence = librosa.segment.recurrence_matrix(mfccs) >>> struct = librosa.segment.structure_feature(recurrence)
Invert the structure feature to get a recurrence matrix
>>> recurrence_2 = librosa.segment.structure_feature(struct, ... inverse=True)
Display recurrence in time-time and time-lag space
>>> import matplotlib.pyplot as plt >>> plt.figure(figsize=(10, 5)) >>> plt.subplot(1, 2, 1) >>> librosa.display.specshow(recurrence, aspect='equal', x_axis='time', ... y_axis='time') >>> plt.ylabel('Time') >>> plt.title('Recurrence (time-time)') >>> plt.subplot(1, 2, 2) >>> librosa.display.specshow(struct, aspect='auto', x_axis='time') >>> plt.ylabel('Lag') >>> plt.title('Structure feature') >>> plt.tight_layout()