eigenvivek / DiffPose

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

Determine extrinsic camera parameters X-ray #35

Closed Nick19111996 closed 2 months ago

Nick19111996 commented 3 months ago

Hi Vivek,

Thank you for sharing your work.

I am working on adapting the intrinsic and extrinsic camera parameters to the X-ray system that we use in our hospital by using this source --> https://pubmed.ncbi.nlm.nih.gov/27431651/ . The intrinsic parameters have been modified according to the parameters of our X-ray device, but I am uncertain about how to determine the extrinsic parameters for our system.

I assume the extrinsic parameters are related to a rigid transformation from the CT coordinate system to the X-ray image coordinate system and therefore determine the starting position of the virtual X-ray source. How can I determine this extrensic matrixt? Can I determine the translation part of the extrinsic matrix using the CT origin, center of rotation, or position of the detector?

Looking forward hearing from you,

Greetings, Nick

eigenvivek commented 3 months ago

Hi Nick, determining the extrinsic of clinical data without ground truth fiducial markers is tricky. As the paper you linked suggests, you can identify paired markers in the 2D and 3D image and run the DLT to estimate the extrinsic (your interpretation of what the extrinsic parameters represent is correct). Another alternative is to use DiffDRR (or any optimization-based 2D/3D registration method) to hunt around for a good extrinsic camera pose. But again, without fiducials, you won't have a ground truth set of extrinsics.

eigenvivek commented 3 months ago

Some DICOM headers (e.g., X-ray angiography) include a 3-DoF set of extrinsics. However, in addition to missing the 3 other DoFs, these parameters also don't account for motion of the patient whereas a true extrinsic camera pose does.

Nick19111996 commented 3 months ago

Thank you for your quick response. Unfortunately, I cannot find a set of extrensics in the output of a C-arm. To solve the issue, I was trying to use DiffDRR to find a good extrinsic camera pose o a lateral (left) image of the pelvis. I found the following rotatation matrix and translation matrix that gave a good lateral DRR: angles = np.array([ [1, 0, 0], [0, -1 , 0], [0, 0, -1]]) translationsmm = [350, 80, 200]

This results in the following transformation matrix:

extrinsic = np.array([              
        [ 1,   0,   0,   350],
        [  0,  -1,   0,   80],
        [  0,   0,   -1,   200],
        [  0,   0,   0 ,    1]
        ], dtype=np.float32)

However, when I use the translation and rotation from the extrinsic paramers in the ipcai Deepfluorodataset to the first volume in Deepfluorodataset, I get an error because the translation seems to be far off. Here are the matrices that I obtained from the extrinsic matrix:

extrinsic = np.array([              
        [ 0.001417,   0.000006,    0.999999, -157.58221],
        [  -0.999991,   -0.004076,    0.001417,   -2.67575],
        [   0.004076,   -0.999992,   -0,       -631.7765],
        [   0,          0,          0 ,  1]
        ], dtype=np.float32)
angles = np.array([ [0.001417,   0.000006,    0.999999],
                    [  -0.999991,   -0.004076,    0.001417],
                    [   0.004076,   -0.999992,   -0]
                    ], dtype=np.float32)
translationsmm = [-157.58221, -2.67575, -631.7765]

It seems like the translation in the extrensic matrix cannot be directly used as a translation for the input of DiffDRR and vice versa. How should I adjust this? Is it neccesary to adjust for the origin of the CT data or the isocentre?

Thank you very much for your help.

eigenvivek commented 2 months ago

I @Nick19111996, sorry for the late reply on this. Are you still encountering issues with this?

In case it's helpful, I updated the pose parameterizations to be compatible with the latest version of DiffDRR, which adjusts for the variable isocenters of CT data: https://github.com/eigenvivek/DiffDRR-Datasets