docs: def imagej_metadata_tag(metadata, byteorder):
      """Return IJMetadata and IJMetadataByteCounts tags from metadata dict.
  
      The tags can be passed to the TiffWriter.save function as extratags.
  
      The metadata dict may contain the following keys and values:
  
          Info : str
              Human-readable information as string.
          Labels : sequence of str
              Human-readable labels for each channel.
          Ranges : sequence of doubles
              Lower and upper values for each channel.
          LUTs : sequence of (3, 256) uint8 ndarrays
              Color palettes for each channel.
          Plot : bytes
              Undocumented ImageJ internal format.
          ROI: bytes
              Undocumented ImageJ internal region of interest format.
          Overlays : bytes
              Undocumented ImageJ internal format.
  
      """
      header = [{'>': b'IJIJ', '<': b'JIJI'}[byteorder]]
      bytecounts = [0]
      body = []
  
      def _string(data, byteorder):
          return data.encode('utf-16' + {'>': 'be', '<': 'le'}[byteorder])
  
      def _doubles(data, byteorder):
          return struct.pack(byteorder+('d' * len(data)), *data)
  
      def _ndarray(data, byteorder):
          return data.tobytes()
  
      def _bytes(data, byteorder):
          return data
  
      metadata_types = (
          ('Info', b'info', 1, _string),
          ('Labels', b'labl', None, _string),
          ('Ranges', b'rang', 1, _doubles),
          ('LUTs', b'luts', None, _ndarray),
          ('Plot', b'plot', 1, _bytes),
          ('ROI', b'roi ', 1, _bytes),
          ('Overlays', b'over', None, _bytes))
  
      for key, mtype, count, func in metadata_types:
          if key.lower() in metadata:
              key = key.lower()
          elif key not in metadata:
              continue
          if byteorder == '<':
              mtype = mtype[::-1]
          values = metadata[key]
          if count is None:
              count = len(values)
          else:
              values = [values]
          header.append(mtype + struct.pack(byteorder+'I', count))
          for value in values:
              data = func(value, byteorder)
              body.append(data)
              bytecounts.append(len(data))
  
      if not body:
          return ()
      body = b''.join(body)
      header = b''.join(header)
      data = header + body
      bytecounts[0] = len(header)
      bytecounts = struct.pack(byteorder+('I' * len(bytecounts)), *bytecounts)
      return ((50839, 'B', len(data), data, True),
              (50838, 'I', len(bytecounts)//4, bytecounts, True))