eigenvivek / DiffPose

[CVPR 2024] Intraoperative 2D/3D registration via differentiable X-ray rendering
http://vivekg.dev/DiffPose/
MIT License
109 stars 11 forks source link

How to obtain internal and external parameters of C-arm machine? #24

Closed 98zhenyu closed 3 months ago

98zhenyu commented 4 months ago

Dear Vivek, If I collect an X-ray image intraoperatively, how do I obtain its corresponding intrinsic and extrinsic parameters (or GT pose) from the Dicom metadata? Does the GT pose of this X-ray image depend on external parameters? On the other hand, if I want to mark fiducial points on CT for subsequent evaluation, in what coordinate system should the points be marked? World coordinates or volume coordinates?

eigenvivek commented 4 months ago

Hi @98zhenyu , this is a bit of a complicated answer. It depends on the scanner you're using and how the manufacturer encodes camera pose parameters in DICOM. Here's what's worked for me (based on data from a Siemens scanner), hopefully it can apply to your data.

The following parameters in DICOM correspond to the following parameters in diffdrr.drr.DRR

The following parameters are used to get the pose

To construct the pose, use the following

from diffdrr.pose import convert

rot = torch.tensor([[alpha, beta, 0.0]]) / 180 * torch.pi # DiffDRR uses radians
xyz = torch.tensor([[0.0, by, 0.0]])
pose = convert(rotations, translations, parameterization="euler_angles", convention="ZXY")

There's a chance that some of these parameters should be negative to comply with clockwise/counterclockwise conventions used by different vendors. Try it out and let me know if you have any issues!

98zhenyu commented 4 months ago

Thank you for your quick reply! At present, I am using the data of GE devices, but I have not found the parameters related to Pose in Dicom Tags. Does it require additional Settings or does the device not have such parameters?

In addition, it seems that the pose parameters you collected on Siemens scanner did not have gamma, bx and bz. Is the GT pose constructed without these three parameters accurate?

eigenvivek commented 4 months ago

i’ve only seen pose parameters in x-ray angiography DICOMs. standard diagnostic x-rays might not have them.

you’re right that gamma, bx, and bz are not in the tags i listed. for bx and bz, there are tags that tell you the position of the bed. in theory, those decode into bx and bz, but i don’t have access to any DICOMs with those. furthermore, i don’t think there’s a DICOM tag for a tertiary angle, e.g., gamma.

final point - even if you have those parameters, the pose you get from DICOM doesn’t account for patient motion. it only tells you where the C-arm is located. so you still have to run test-time optimization to solve for the motion of the patient.

98zhenyu commented 4 months ago

If there is no GT pose parameter in the standard diagnostic X-ray, how can I judge the accuracy of a specific pose estimation model for preoperative CT training of a new patient? Comparing the image similarity between DRR and real X-rays does not seem convincing enough.

eigenvivek commented 4 months ago

If you don't have GT pose parameters, you're out of luck. You need either implanted fiducial markers (best option) or DICOM pose parameters (second-best option) to independently validate the results of the registration.

I've seen some other validation strategies when these mechanisms aren't available.

However, these strategies are dependent on your registration pipeline (i.e., the renderer, optimizer, and loss function). It's not an independent validation mechanism, but sometimes it's the best you can do.

98zhenyu commented 4 months ago

Unfortunately, it seems that it is very difficult to construct clinical real-world datasets for X-ray images and CT registration, and it is not easy to obtain both implanted fiducial markers and GT pose. I will try to collect some clinical data again.

By the way, currently it takes more than ten hours to train a specific pose estimation model for each CT case. Do you have any good ideas for reducing training time or enhancing generalization? This will help me a lot.

eigenvivek commented 3 months ago

You could always try running a model trained on one patient on another. However, DiffPose is really designed to be overfit on a particular patient. If you don't need speed, you might be better served manually finding a good pose and running 2D/3D registration with DiffDRR.

Closing this for now, feel free to open more issues or email me if you have further questions!