matthew-brett / transforms3d

3 dimensional spatial transformations
http://matthew-brett.github.io/transforms3d/
Other
469 stars 83 forks source link

Transformation matrix (affine_matrix_from_points) #57

Open Cestovatels opened 1 year ago

Cestovatels commented 1 year ago

Hello. I have been working on STL and DICOM images for a while. I select points on STL and DICOM with the 3Dslicer program. Then I create a set of v0 and v1 points for myself. Thanks to these points, I am trying to move the STL on DICOM using the function you wrote. I apply the affine_matrix_from_points function to the STL I have, but it does not create an STL where I want. Am I doing something wrong or do I need to change the method?

import numpy as np
from transforms3d import _gohlketransforms
from stl import mesh

v0 = [[-8.7,-13.8,-17.8,-18.5,-18.7,-16.3,-12.6,-7.4],
         [6.2,4.5,2.9,2.4,2.4,3.1,3.5,5.3],
         [17.4,11.9,6.8,1.1,-4.0,-8.8,-14.7,-19.6]]

v1 = [[-88.9,-93.7,-99.0,-104.6,-109.8,-115.9,-121.3,-126.4],
          [-46.2,-40.8,-37.3,-35.5,-35.4,-38.4,-40.8,-45.6],
          [64.3,62.8,62.5,62.5,62.4,63.0,63.7,65.0]]

stl_data = mesh.Mesh.from_file('test.stl')      
R = _gohlketransforms.affine_matrix_from_points(v0, v1,shear=False, scale=False, usesvd=True)
stl_data.transform(R)
stl_data.save('affine_matrix_from_points.stl')
matthew-brett commented 1 year ago

I'm really sorry to say - that I don't know that function at all - it's from the code that became : https://github.com/cgohlke/transformations/blob/master/transformations/transformations.py#L936 - try there for support?

Cestovatels commented 1 year ago

image I have examined this part of the code in detail, but there may be something I missed. In this image, the bottom left part is STL and the skull is DICOM. If I align the two, everything will be solved. Thanks for your help.

matthew-brett commented 1 year ago

Sorry - just to clarify - I can't help - as I don't know the code. Try the repository I linked to above.