align4.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. """Align a set of curves in space
  2. with Procrustes method"""
  3. from vedo import Assembly, dataurl, procrustes_alignment, Line, mag, show
  4. # Load splines from a file (returns a group of vedo.Lines, like a list)
  5. splines = Assembly(dataurl+'splines.npy')
  6. # Perform Procrustes alignment on the splines, allowing for non-rigid transformations
  7. procus = procrustes_alignment(splines, rigid=False)
  8. # Unpack the aligned splines from the Assembly object into a Python list
  9. alignedsplines = procus.unpack()
  10. # Obtain the mean spline and create a Line object with thicker width and blue color
  11. mean = procus.info['mean']
  12. lmean = Line(mean).z(0.001) # z-shift it to make it visible
  13. lmean.linewidth(4).c('blue')
  14. # Color the aligned splines based on their distance from the mean spline
  15. for s in alignedsplines:
  16. darr = mag(s.coordinates - mean) # distance array
  17. s.cmap('hot_r', darr, vmin=0, vmax=0.007)
  18. # Add the mean spline and script description to the list of aligned splines
  19. alignedsplines += [lmean, __doc__]
  20. # Show the original and aligned splines in two side-by-side views
  21. # with independent cameras
  22. show([splines, alignedsplines], N=2, sharecam=False, axes=1).close()