fepegar / resector

Algorithm to simulate resection surgery on brain MRI scans. Published in MICCAI 2020, extended in IJCARS.
https://doi.org/10.1007/s11548-021-02420-2
MIT License
13 stars 4 forks source link

The execution order of the code #14

Open liyunkai-carpediem opened 1 year ago

liyunkai-carpediem commented 1 year ago

Description

I want to delve into the code and not run it as pre-packaged methods. I have found the generated geodesic polyhedron and I would like to ask which part of the code is responsible for adding simplex noise to it , as well as the code for random affine transformations.

fepegar commented 1 year ago

Hi @liyunkai-carpediem. You can just search for the code:

https://github.com/fepegar/resector/blob/ed63b3de5562fb011fb88916c4da8d170415cd6f/resector/mesh.py#L64-L87

https://github.com/fepegar/resector/blob/ed63b3de5562fb011fb88916c4da8d170415cd6f/resector/mesh.py#L109-L124

liyunkai-carpediem commented 1 year ago

Dear sir, Thanks a lot for giving me an answer, I am very excited!!! And I have found the relative codes in the following path: "scripts/test/perlin_sphere.py" I think they are the same(?)

  1. So what is the difference between the folder "scripts" and "resector"?
  2. I have found there is a code called "perlin_image.py", I ran it, getting a result of"simplex.nii", maybe it is a noise for adding it into the sphere? But I noticed that we use “noise” library to do so. So what is the function of "perlin_image.py"?
  3. when I run the following code, I have noticed that there are 5 shapes generated. Which one will be the final shape I will be used later?

    for _ in range(5):
    offset = np.random.randint(1000)
    output_path = f'/tmp/geodesic_polyhedron_noise_{offset}.vtp'
    
    volume = np.random.randint(100, 10000)
    center = np.random.randint(-50, 50, size=(3))
    k = 4/3 * np.pi
    radius = (volume / k) ** (1/3)
    ratio = np.random.uniform(0.8, 1)
    a = radius
    b = radius * ratio
    c = radius / ratio
    radii = a, b, c
    angles = np.random.uniform(0, 180, size=3)
    
    output_poly_data = get_resection_poly_data(
        input_poly_data,
        offset,
        center,
        radii,
        angles,
    )

Thanks a lot.

liyunkai-carpediem commented 1 year ago

When I run the mesh_to_vol, I met some problems. My code is here:

from resector.io import read_poly_data, write
from resector.mesh import mesh_to_volume

mesh_path = '/storage/liyunkai/resector-master/geodesic_polyhedron_noise_102.vtp'
reference_path = '/storage/liyunkai/MICCAI_FeTS2022_TrainingData/FeTS2022_00000/FeTS2022_00000_seg.nii.gz'

poly_data = read_poly_data(mesh_path)

image = mesh_to_volume(poly_data, reference_path)
write(image, '/storage/liyunkai/resector-master/result/stenciled.nii.gz')

And the error is:

/storage/liyunkai/resector-master/resector/mesh.py:281: UserWarning: Empty stencil mask for reference /tmp/tmpub2oik3h.nii
  warnings.warn(f'Empty stencil mask for reference {reference_path}')

the file is empty, but how?