pts_transform_scale.py 910 B

123456789101112131415161718192021222324252627282930313233
  1. import numpy as np
  2. __all__ = ['scale_2d_points']
  3. def scale_2d_points(points, x_scale=1, y_scale=1, x_center=0, y_center=0, copy=True):
  4. """Scale 2d points.
  5. Args:
  6. points: (..., 2N)
  7. x_scale: scale factor in x dimension
  8. y_scale: scale factor in y dimension
  9. x_center: scale center in x dimension
  10. y_center: scale center in y dimension
  11. """
  12. points = np.array(points, dtype=np.float32, copy=copy)
  13. x_scale = np.asarray(x_scale, np.float32)
  14. y_scale = np.asarray(y_scale, np.float32)
  15. x_center = np.asarray(x_center, np.float32)
  16. y_center = np.asarray(y_center, np.float32)
  17. x_shift = 1 - x_scale
  18. y_shift = 1 - y_scale
  19. x_shift *= x_center
  20. y_shift *= y_center
  21. points[..., 0::2] *= x_scale
  22. points[..., 1::2] *= y_scale
  23. points[..., 0::2] += x_shift
  24. points[..., 1::2] += y_shift
  25. return points