-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_source.py
More file actions
37 lines (28 loc) · 1.13 KB
/
Copy pathcreate_source.py
File metadata and controls
37 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import SimpleITK as sitk
import numpy as np
ref_image = sitk.ReadImage('Test_case/attmap_padded.mhd')
origin = ref_image.GetOrigin()
spacing = ref_image.GetSpacing()
image_size = ref_image.GetSize()
sphere_radius = 10 # Radius of the spheres
# Create an empty image
image = sitk.Image(image_size, sitk.sitkUInt8)
# Define the center of the first and second spheres
sphere1_center = [66, 44, 43]
sphere2_center = [35, 70, 60]
# Function to add a sphere to an image
def add_sphere(image, center, radius):
for x in range(image.GetSize()[0]):
for y in range(image.GetSize()[1]):
for z in range(image.GetSize()[2]):
if np.sum((np.array([x, y, z]) - center)**2) <= radius**2:
image.SetPixel([x, y, z], 100) # Set voxel inside the sphere to 1
return image
# Add the two spheres to the image
image = add_sphere(image, sphere1_center, sphere_radius/3)
image = add_sphere(image, sphere2_center, sphere_radius)
# Set origin and center
image.SetOrigin(origin)
image.SetSpacing(spacing)
# Save the image in MetaImage (.mhd) format
sitk.WriteImage(image, "Test_case/source_padded.mhd")