arcadelab / deepdrr

Code for "DeepDRR: A Catalyst for Machine Learning in Fluoroscopy-guided Procedures". https://arxiv.org/abs/1803.08606
GNU General Public License v3.0
209 stars 60 forks source link

Source detector distance / perspective question #80

Closed hemmer closed 1 year ago

hemmer commented 1 year ago

Hi there - I have mismatch between my intuition about what the MobileCArm source_to_detector_distance parameter should do and what I see.

image

For a fixed sensor size, I might expect for small source_to_detector_distance that the front and back faces of the cube are well separated (d1 big), and for large source_to_detector_distance the opposite (d2 smaller). Also for large source_to_detector_distance I would expect the volume to appear smaller on the rendered image. However for a toy minimal example I get different behaviour:

https://gist.github.com/hemmer/0c48d0d5ba9526e666d03cb0dbe35c25

I observe no change in separation between front and back faces, and the volume appears larger for big source_to_detector_distance.

I suspect this may be due to differences in intrinsic and extrinsic parameters that are a bit above my head at the moment. My questions are:

For context, i see the behaviour i'd expect from DiffDRR (see end of minimal example) - I'm sure it's just a convention/parameterisation thing, but it'd be nice to reconcile these approaches.

mathiasunberath commented 1 year ago

Based on what I see in your second set of examples, it's working as expected. If you look at it's edges parallel to the principle ray of the C-arm, you will see the divergent beam effect exactly as you describe it. There do seem however to be other things going on also, because a SID of 100 is very different from a SID of 1600 - clearly, very differently sized objects will fit in there, however, your objects always fill around the same space in these simulations. Thus, there is something else going on at the same time.

hemmer commented 1 year ago

Based on what I see in your second set of examples, it's working as expected. If you look at it's edges parallel to the principle ray of the C-arm, you will see the divergent beam effect exactly as you describe it.

Just to clarify in case you missed it the second set of examples is with a different library (diffdrr).

There do seem however to be other things going on also, because a SID of 100 is very different from a SID of 1600 - clearly, very differently sized objects will fit in there, however, your objects always fill around the same space in these simulations. Thus, there is something else going on at the same time.

I think in the DiffDRR library there is an implicit linear scaling of the detector real world size with SDR. If this is corrected/undone then you get the behaviour you'd expect I think:

image

benjamindkilleen commented 1 year ago

Looking at your minimal example, my first instinct is that you are not positioning the C-arm correctly. There are two variables at play here: source_to_detector_distance and source_to_isocenter_distance, as well as the placement of the virtual C-arm isocenter. If you double the SDR, be sure to double the isocenter distance as well. Thus you might be getting secondary effects from the phantom being in different places than you expect it.

hemmer commented 1 year ago

Thanks for your help, scaling source_to_isocenter_vertical_distance linearly with sdr achieves the effect I was expecting. I'll update this thread with an updated notebook, then close the issue.

hemmer commented 1 year ago

Updated notebook here:

https://gist.github.com/hemmer/a5e1aea1bccaa2aa89dba5df93ffd8ca

fedeface98 commented 11 months ago

Hello @hemmer,

Can I ask you why in the function Volume.from_parameters you put anatomical_coordinate_system=None and world_from_anatomical=None ?

Thanks for sharing your notebook!

benjamindkilleen commented 11 months ago

I can comment on what this would do.

anatomical_coordinate_system only needs to be set when interacting with annotations. It is meant to avoid a situation where one volume was loaded from a NRRD file in LPS coordinates and another from a NIFTI file in RAS coordinates. It's usually set automatically when using the from_FORMAT loaders.

world_from_anatomical=None simply sets this to the identity transform, so the world frame is the same as the anatomical frame.