Git Product home page Git Product logo

Comments (11)

lkccu avatar lkccu commented on June 6, 2024

Here are the codes.

volume = deepdrr.Volume.from_nifti(path,
                                  materials ='Bone')

camera_intrinsics = deepdrr.geo.CameraIntrinsicTransform.from_sizes(
    sensor_size = 512,
    pixel_size = 0.5,
    source_to_detector_distance = 1118.38
)
center = volume.world_from_ijk @ deepdrr.geo.point(160,160,160)
carm = deepdrr.MobileCArm(isocenter=center,
                          source_to_detector_distance = 689.1,
                         min_alpha = -40,
                         max_alpha = 40,
                         # note that this would collide with the patient. Suggested to limit to +/- 45
                         min_beta = -45,
                         max_beta = 45,
                         pixel_size =0.5,
                         sensor_height =320,
                         sensor_width =320,)

alphas,betas = utils.generate_uniform_angles(
    (-40,40,40),
    (-45,45,45)
)

output_dir = Path("/root/autodl-tmp/drr_result")
output_dir.mkdir(exist_ok = True)
with deepdrr.Projector(
    volume=volume,
    carm=carm,
    step=0.1,  # stepsize along projection ray, measured in voxels
    spectrum="90KV_AL40", # energy spectrum
    photon_count=100000, # number of photons to simulate
    scatter_num=0, # number of scatter events to simulate
    neglog=True, # apply negative log transform to image (convenient for visualization)
    intensity_upper_bound=3, # Good default for windowing
    
) as projector:
    images = projector.project_over_carm_range(
          (-40,40,40),
          (-45,45,45))
    for i,image in enumerate(images):
        plt.imshow(image,cmap ='gray')
        plt.title(f'alpha,beta ={alphas[i],betas[i]}')
        display(Image.fromarray((image * 255).astype(np.uint8)))
print("###               finish               ###")

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

And how can I make use of the arg materials,I searched that in issues and I found materials = dict["bone = seg_array"] ,but I am not sure how can I specify the seg_array variable or there is a solution? Thanks
Regards.

from deepdrr.

mathiasunberath avatar mathiasunberath commented on June 6, 2024

@benjamindkilleen you want to take a look at this?

from deepdrr.

benjamindkilleen avatar benjamindkilleen commented on June 6, 2024

@lkccu The first issue is because project_over_carm_range works with the CArm class and not the MobileCArm class. (This will raise an error in future releases.) I recommend to update the pose of the carm directly with the carm.move_to function, using the alphas,betas you have defined, and calling the projector for each image. (This is what project_over_carm_range does under the hood.

For the latter issue, it would be materials = dict(bone=seg_array), where seg_array is a 3D numpy binary array giving the segmentation of bone. This is syntactically equal to materials = {"bone": seg_array}, which may be more familiar. The materials argument should be the whole dictionary.

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

Thank you for that, I mistakes what arg material is doing. So does that mean 'material' is doing seg from an known segmentation nifti data?what should I do to generate a bone-styled DRR image from scratch?
Regards.

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

I specify in the volume that "segmentation = True", however I got an terrible result.I wonder whether it is because my data is not that good.Can you give me a hand?Here is the minimum example .
Q%}B1`NWZ1W)@}1K5DKE3Z9
before seg.
image

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

Hi author @mathiasunberath, happy CNY!I have encountered the same trouble now.I wonder how can I make use of sample nifti image dataset6_CLINIC_0001_mask_4label_1.nii.gz.I inspected in Slicer and that seg mask looks so great.However,when I tried to load it as a 3-d array and specify arg materials in func Volume.from_nifti, it turned out a dark image.Could you please give me a hand?Thank you very much!The codes are as follows.

seg_array = nib.load('/root/autodl-tmp/datasets/DeepDRR_Data/CTPelvic1K_dataset6_CLINIC_0001/dataset6_CLINIC_0001_mask_4label_1.nii.gz')
print(seg_array.shape)
seg_array = seg_array.get_fdata()
volume = deepdrr.Volume.from_nifti(path,
                                   materials=dict(bone=seg_array))             
volume.supine()
carm = deepdrr.MobileCArm(isocenter=volume.center_in_world, alpha=0, beta=0, degrees=True)

with deepdrr.Projector(
    volume=volume,
    carm=carm,
    step=0.2,  # stepsize along projection ray, measured in voxels
    spectrum="90KV_AL40", # energy spectrum
    photon_count=10000, # number of photons to simulate
    scatter_num=0, # number of catter events to simulate
    collected_energy =False, # apply negative log transform to image (convenient for visualization)
    intensity_upper_bound=2, # Good default for windowing
) as projector:
    for z in range(-500, -100, 50):
        carm.move_to(isocenter_in_world=volume.center_in_world + geo.v(0, 0, z))
        print(f"Projecting at z={z}")
        image = projector.project()
        display(Image.fromarray((image * 255).astype(np.uint8)))
print("######          finish          ######") 

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

Hi author!

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

Hello,I am wondering what can I do in my func to ensure that the projector is initialized or set it initialized?

from deepdrr.

benjamindkilleen avatar benjamindkilleen commented on June 6, 2024

projector.initialize(), which is a no-op if already initialized.

from deepdrr.

lkccu avatar lkccu commented on June 6, 2024

projector.initialize(), which is a no-op if already initialized.
Thank you.I want to initialized the projector in the beginning of code and turn it into a parameter of functions like
drr(projector=projector, rtvec=X) where function drr is generating drr images of the very volume rotating and translating ,carm.What should I do?Please give me a hand.

from deepdrr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.