code: def convert_dense_to_sparse(dense, validate=True):
      if validate:
          _validate_dense(dense)
  
      full_shape = dense.shape
      label_dim = full_shape[DENSE_AXIS.label_idx.value]
      dense_shape = tuple(
          [full_shape[DENSE_AXIS[n].value] for n in DENSE_SHAPE_NAMES]
      )
  
      axes_labels = np.array(SPARSE_AXES_FIELDS)
      axes = axes_labels[np.where(np.array(dense_shape) > 1)]
  
      compact = np.squeeze(dense)
      if label_dim == 1:
          compact = np.expand_dims(compact, axis=0)
  
      coords = np.where(compact != 0)
      labels = compact[coords]
      # no longer need the labels dim
      coords = coords[1:]
  
      if np.max(compact.shape) < 2**16:
          coords_dtype = np.uint16
      else:
          coords_dtype = np.uint32
  
      if len(labels) > 0:
          max_label = np.max(labels)
          if max_label < 2**8:
              labels_dtype = np.uint8
          elif max_label < 2**16:
              labels_dtype = np.uint16
          else:
              labels_dtype = np.uint32
      else:
          labels_dtype = np.uint8
  
      dtype = [(axis, coords_dtype) for axis in axes]
      dtype.append((SPARSE_FIELD.label.value, labels_dtype))
      sparse = np.core.records.fromarrays(
          list(coords) + [labels], dtype=dtype
      )
  
      return sparse
  
imports: from enum import Enum
  import numpy
  from numpy.random.mtrand import RandomState
  import scipy.sparse
  import centrosome.index
label_desc: Use image node_id 16 for calling a global function with example usage: convert_dense_to_sparse(dense, validate) and returns: sparse