code: def avgze(image):
      # since we use histograms
      if image.format != "uchar" and image.format != "ushort":
          raise Exception("uchar and ushort images only")
  
      # take the histogram, and set the count for 0 pixels to 0, removing them
      histze = image.hist_find().insert(pyvips.Image.black(1, 1), 0, 0)
  
      # number of non-zero pixels in each band
      nnz = [
          histze[i].avg() * histze.width * histze.height
          for i in range(histze.bands)
      ]
  
      # multiply by the identity function and we get the sum of non-zero
      # pixels ... for 16-bit images, we need a larger identity
      # function
      totalze = histze * pyvips.Image.identity(
          ushort=histze.width > 256
      )
  
      # find average value in each band
      avgze = [
          totalze[i].avg() * histze.width * histze.height / nnz[i]
          for i in range(totalze.bands)
      ]
  
      return avgze
  
label_desc: Use image node_id 1 for calling a global function with example usage: avgze(image) and returns: avgze