code: def spectral_diff(spectrogram, diff_frames=None):
      """
      Spectral Diff.
  
      Parameters
      ----------
      spectrogram : :class:`Spectrogram` instance
          Spectrogram instance.
      diff_frames : int, optional
          Number of frames to calculate the diff to.
  
      Returns
      -------
      spectral_diff : numpy array
          Spectral diff onset detection function.
  
      References
      ----------
      .. [1] Chris Duxbury, Mark Sandler and Matthew Davis,
             "A hybrid approach to musical note onset detection",
             Proceedings of the 5th International Conference on Digital Audio
             Effects (DAFx), 2002.
  
      """
      from madmom.audio.spectrogram import SpectrogramDifference
  
      # if the diff of a spectrogram is given, do not calculate the diff twice
      if not isinstance(spectrogram, SpectrogramDifference):
          spectrogram = spectrogram.diff(
              diff_frames=diff_frames, positive_diffs=True
          )
      # Spectral diff is the sum of all squared positive 1st order differences
      return np.asarray(np.sum(spectrogram**2, axis=1))
  
imports: from __future__ import absolute_import, division, print_function
  import numpy
  from scipy.ndimage import maximum_filter, minimum_filter, uniform_filter
  from ..audio.signal import smooth
  from ..processors import BufferProcessor, OnlineProcessor, ParallelProcessor, SequentialProcessor
  from ..utils import combine_events
label_desc: Use image node_id 4 for calling a global function with example usage: spectral_diff(spectrogram, diff_frames) and returns: np