arcadelab/deepdrr

mapping 3D to 2D points

yg97avef opened this issue · 7 comments

Hello, I have a small question regarding projections.

I have some annotations for my CT data in 3D world coordinate space. Is there is a way to find the transformed 2D point of this annotation on the generated x-ray image?

Yes.
If it's points then you can use the projection geometry to project into 2D.
If it's segmentation maps then you can project using a MIP. We have this setup internally, though @benjamindkilleen would know best whether it's currently available anywhere on our public branches.

@yg97avef Yes, this functionality is definitely there. Say you have a CameraProjection object as defined in geo.py, and the points you want to transform are in a (N, 3) array called points. Then you would do

from deepdrr import geo

# points: (N,3) numpy array
# camera_projection: geo.CameraProjection
points_world = [geo.point(p) for p in points]
points_index = [camera_projection.index_from_world @ p for p in points_world]

You could then convert points_index back to numpy with np.array. geo.py currently works on individual points right now, so the list comprehensions are necessary.

@benjamindkilleen That works fine! Thank you :)

@benjamindkilleen What are the differences between using the CameraProjection and the projection described in https://github.com/mathiasunberath/AnatomicalLandmarks/blob/master/projection.m ?

Functionally, there is no difference. CameraProjection is a Python class containing the matrices described in that example.

@benjamindkilleen Thanks for the answer.

By the way, for reference for others, I got the projection like so:
camera_projection: geo.CameraProjection = c_arm.get_camera_projection(),
where c_arm is the same C arm that projects the volume to a DRR.

hello, I want to mapping 3D points to 2D point. I use this code :
points = np.array([[238, 332, 304],
[614, 357, 298],
[363, 306, 159]])
camera_projection = geo.CameraProjection
points_world = [geo.point(p) for p in points]
points_index = [np.dot(camera_projection.index_from_world, p) for p in points_world]
But, the code reported an error
“raceback (most recent call last):
File "/home/cui/Deepdrr/keypoint.py", line 120, in
points_index = [np.dot(camera_projection.index_from_world, p) for p in points_world]
File "/home/cui/Deepdrr/keypoint.py", line 120, in
points_index = [np.dot(camera_projection.index_from_world, p) for p in points_world]
File "<array_function internals>", line 200, in dot
TypeError: unsupported operand type(s) for *: 'property' and 'float'

May I ask how I should solve it?