eigenvivek / DiffDRR

Auto-differentiable digitally reconstructed radiographs in PyTorch
https://vivekg.dev/DiffDRR
MIT License
148 stars 21 forks source link

Regarding the quality issues of the DRR image. #344

Closed linquanxu closed 1 week ago

linquanxu commented 2 weeks ago

Dear author, I used this code to generate DRR images, but I found that the generated DRR image is very different from the real X-ray image. The generated DRR image is very blurry, while the real X-ray image is much clearer. Could you please help me understand what might be causing this issue? Below are the generated images and the code.

    subject = read(volume='./data/11Spine10B30s')

    # Make a mesh from the CT volume
    ct = drr_to_mesh(subject, "surface_nets", threshold=225, verbose=True)
    SDD = 2000
    HEIGHT = 256
    DELX = 7.1942
    # Initialize the DRR module for generating synthetic X-rays
    drr = DRR(subject, sdd=SDD, height=HEIGHT, delx=DELX).to(device)
    # Make a pose
    rot = torch.tensor([[0.0, 0.0, 0.0]], device=device) / 180 * torch.pi
    xyz = torch.tensor([[0.0, 600.0, 0.0]], device=device)
    pose = convert(rot, xyz, parameterization="euler_angles", convention="ZXY")
    img = drr(pose)
    plot_drr(img)
    plt.savefig("drr_image_plot.jpg")
    plt.show()

image image Additionally, in the DRR image, the area I marked in red appears abnormal. What could be causing this issue?

Lastly, I have attached the real X-ray image below: image

eigenvivek commented 1 week ago

Hi @linquanxu, a few things I would try:

Hope that helps, let me know if you have further questions!

linquanxu commented 1 week ago

Hi, @eigenvivek, Thank you for your quick response.

  1. The real X-ray image has a PixelSpacing of 0.139 and a DistanceSourceToDetector of 2000.

  2. In the CT DICOM, the PixelSpacing is 0.373, the DistanceSourceToDetector is 1085.6, the DistanceSourceToPatient is 595, and the SliceThickness is 1.0.

How should I set the parameters to make the generated DRR image as close as possible to the real X-ray image? Should I fully follow the parameters of the real X-ray equipment in this case?

eigenvivek commented 1 week ago

Yes, follow the parameters of the real X-ray for your DRR.

diffdrr.data.read should exactly extract the parameters from the CT DICOM.

Real X-rays are very large, and rendering a DRR that big will likely use more memory than you have on your GPU. To overcome this, you can downsample the detector (diffdrr.DRR.rescale_detector_) or use the patch_size argument.

linquanxu commented 1 week ago

Thank you for your help, I'll try again.