docs: def imagej_metadata(data, bytecounts, byteorder):
      """Return IJMetadata tag value as dict.
  
      The 'Info' string can have multiple formats, e.g. OIF or ScanImage,
      that might be parsed into dicts using the matlabstr2py or
      oiffile.SettingsFile functions.
  
      """
      def _string(data, byteorder):
          return data.decode('utf-16' + {'>': 'be', '<': 'le'}[byteorder])
  
      def _doubles(data, byteorder):
          return struct.unpack(byteorder+('d' * (len(data) // 8)), data)
  
      def _lut(data, byteorder):
          return numpy.frombuffer(data, 'uint8').reshape(-1, 256)
  
      def _bytes(data, byteorder):
          return data
  
      metadata_types = {  # big-endian
          b'info': ('Info', _string),
          b'labl': ('Labels', _string),
          b'rang': ('Ranges', _doubles),
          b'luts': ('LUTs', _lut),
          b'plot': ('Plots', _bytes),
          b'roi ': ('ROI', _bytes),
          b'over': ('Overlays', _bytes)}
      metadata_types.update(  # little-endian
          dict((k[::-1], v) for k, v in metadata_types.items()))
  
      if not bytecounts:
          raise ValueError('no ImageJ metadata')
  
      if not data[:4] in (b'IJIJ', b'JIJI'):
          raise ValueError('invalid ImageJ metadata')
  
      header_size = bytecounts[0]
      if header_size < 12 or header_size > 804:
          raise ValueError('invalid ImageJ metadata header size')
  
      ntypes = (header_size - 4) // 8
      header = struct.unpack(byteorder+'4sI'*ntypes, data[4:4+ntypes*8])
      pos = 4 + ntypes * 8
      counter = 0
      result = {}
      for mtype, count in zip(header[::2], header[1::2]):
          values = []
          name, func = metadata_types.get(mtype, (bytes2str(mtype), read_bytes))
          for _ in range(count):
              counter += 1
              pos1 = pos + bytecounts[counter]
              values.append(func(data[pos:pos1], byteorder))
              pos = pos1
          result[name.strip()] = values[0] if count == 1 else values
      return result