code: def transform_from_stats(stats, inverse=False):
      # https://cookierobotics.com/007/
      a = stats.varianceX
      b = stats.covariance
      c = stats.varianceY
  
      delta = (((a - c) * 0.5) ** 2 + b * b) ** 0.5
      lambda1 = (a + c) * 0.5 + delta  # Major eigenvalue
      lambda2 = (a + c) * 0.5 - delta  # Minor eigenvalue
      theta = (
          atan2(lambda1 - a, b)
          if b != 0
          else (pi * 0.5 if a < c else 0)
      )
      trans = Transform()
  
      if lambda2 < 0:
          # XXX This is a hack.
          # The problem is that the covariance matrix is singular.
          # This happens when the contour is a line, or a circle.
          # In that case, the covariance matrix is not a good
          # representation of the contour.
          # We should probably detect this earlier and avoid
          # computing the covariance matrix in the first place.
          # But for now, we just avoid the division by zero.
          lambda2 = 0
  
      if inverse:
          trans = trans.translate(-stats.meanX, -stats.meanY)
          trans = trans.rotate(-theta)
          trans = trans.scale(1 / sqrt(lambda1), 1 / sqrt(lambda2))
      else:
          trans = trans.scale(sqrt(lambda1), sqrt(lambda2))
          trans = trans.rotate(theta)
          trans = trans.translate(stats.meanX, stats.meanY)
  
      return trans
  
imports: from fontTools.ttLib.ttGlyphSet import LerpGlyphSet
  from fontTools.pens.basePen import AbstractPen, BasePen, DecomposingPen
  from fontTools.pens.pointPen import AbstractPointPen, SegmentToPointPen
  from fontTools.pens.recordingPen import RecordingPen, DecomposingRecordingPen
  from fontTools.misc.transform import Transform
  from collections import defaultdict, deque
  from math import sqrt, copysign, atan2, pi
  from enum import Enum
  import itertools
  import logging
label_desc: Use image node_id 15 for calling a global function with example usage: transform_from_stats(stats, inverse) and returns: trans