Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One mode ellipsoid #1158

Closed
wants to merge 11 commits into from
3 changes: 0 additions & 3 deletions Examples/Python/Data/ellipsoid-v0.zip

This file was deleted.

3 changes: 3 additions & 0 deletions Examples/Python/Data/ellipsoid_1mode.zip
Git LFS file not shown
3 changes: 0 additions & 3 deletions Examples/Python/Data/ellipsoid_fd-v0.zip

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def Run_Pipeline(args):
if int(args.interactive) != 0:
input("Press Enter to continue")
# Get data
datasetName = "ellipsoid-v1"
datasetName = "ellipsoid_1mode"
outputDirectory = "Output/ellipsoid/"
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def Run_Pipeline(args):
if int(args.interactive) != 0:
input("Press Enter to continue")
# Get data
datasetName = "ellipsoid_aligned-v1"
datasetName = "ellipsoid_1mode_aligned"
outputDirectory = "Output/ellipsoid_cut/"
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
Expand Down
8 changes: 4 additions & 4 deletions Examples/Python/ellipsoid_fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def Run_Pipeline(args):
if int(args.interactive) != 0:
input("Press Enter to continue")

datasetName = "ellipsoid_fd-v0"
datasetName = "ellipsoid_1mode"
outputDirectory = "Output/ellipsoid_fd/"
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
CommonUtils.download_and_unzip_dataset(datasetName, outputDirectory)

fileListDT = sorted(glob.glob(outputDirectory + datasetName + "/distance_transforms/*.nrrd"))
fileListNew = sorted(glob.glob(outputDirectory + datasetName + "/new_distance_transforms/*.nrrd"))
fileListDT = sorted(glob.glob(outputDirectory + datasetName + "/groomed/distance_transforms/*.nrrd"))
fileListNew = sorted(glob.glob(outputDirectory + datasetName + "/fd_segmentations/*.nrrd"))

"""
## GROOM : Data Pre-processing
Expand Down Expand Up @@ -86,7 +86,7 @@ def Run_Pipeline(args):
Evaluate the meanshape of the existing shape model and use that to initialize the
particles on the new shapes
"""
shapemodelDir = outputDirectory + datasetName + "/shape_models/pretrained/128/"
shapemodelDir = outputDirectory + datasetName + "/shape_models/ellipsoid/128/"
print(os.listdir(shapemodelDir))
findMeanShape(shapemodelDir)
meanShapePath = shapemodelDir + '/meanshape_local.particles'
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/ellipsoid_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def Run_Pipeline(args):
if int(args.interactive) != 0:
input("Press Enter to continue")

datasetName = "ellipsoid-v0"
datasetName = "ellipsoid_1mode_aligned"
outputDirectory = "Output/ellipsoid_mesh/"
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"After you login, click `Collections` on the left panel and then `use-case-data-v2`. Select the dataset you would like to download by clicking on the checkbox on the left of the dataset name. See the video below.\n",
"After you download the dataset zip file, make sure you unzip/extract the contents in the appropriate location.\n",
"\n",
"**This notebook assumes that you have downloaded `ellipsoid-v1` and you have placed the unzipped folder `ellipsoid-v1` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"**This notebook assumes that you have downloaded `ellipsoid_1mode` and you have placed the unzipped folder `ellipsoid_1mode` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"\n",
"\n",
"<p><video src=\"https://sci.utah.edu/~shapeworks/doc-resources/mp4s/portal_data_download.mp4\" autoplay muted loop controls style=\"width:100%\"></p>"
Expand All @@ -311,7 +311,7 @@
"outputs": [],
"source": [
"# dataset name is the folder name for your dataset\n",
"datasetName = 'ellipsoid-v1'\n",
"datasetName = 'ellipsoid_1mode'\n",
"\n",
"# path to the dataset where we can find shape data \n",
"# here we assume shape data are given as binary segmentations\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@
"After you login, click `Collections` on the left panel and then `use-case-data-v2`. Select the dataset you would like to download by clicking on the checkbox on the left of the dataset name. See the video below.\n",
"After you download the dataset zip file, make sure you unzip/extract the contents in the appropriate location.\n",
"\n",
"**This notebook assumes that you have downloaded `ellipsoid-v1` and you have placed the unzipped folder `ellipsoid-v1` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"**This notebook assumes that you have downloaded `ellipsoid_1mode` and you have placed the unzipped folder `ellipsoid_1mode` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"\n",
"\n",
"<p><video src=\"https://sci.utah.edu/~shapeworks/doc-resources/mp4s/portal_data_download.mp4\" autoplay muted loop controls style=\"width:100%\"></p>"
Expand All @@ -656,7 +656,7 @@
"import glob # for paths and file-directory search\n",
"from pathlib import Path # for generating robust paths irrespective of the platform:Win/Linux/Mac\n",
"# dataset name is the folder name for your dataset\n",
"datasetName = 'ellipsoid-v1'\n",
"datasetName = 'ellipsoid_1mode'\n",
"\n",
"# file extension for the shape data\n",
"shapeExtention = '.nrrd'\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"\n",
"After you login, click `Collections` on the left panel and then `use-case-data-v2`. Select the dataset you would like to download by clicking on the checkbox on the left of the dataset name. See the video below.\n",
"\n",
"**This notebook assumes that you have downloaded `ellipsoid-v1` and you have placed the unzipped folder`ellipsoid-v1`in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"**This notebook assumes that you have downloaded `ellipsoid_1mode` and you have placed the unzipped folder`ellipsoid_1mode`in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"\n",
"\n",
"<p><video src=\"https://sci.utah.edu/~shapeworks/doc-resources/mp4s/portal_data_download.mp4\" autoplay muted loop controls style=\"width:100%\"></p>\n",
Expand All @@ -144,7 +144,7 @@
"import os # for paths and mkdir\n",
"\n",
"# dataset name is the folder name for your dataset\n",
"datasetName = 'ellipsoid-v1'\n",
"datasetName = 'ellipsoid_1mode'\n",
"\n",
"# path to the dataset where we can find shape data \n",
"# here we assume shape data are given as surface meshes\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"After you login, click `Collections` on the left panel and then `use-case-data-v2`. Select the dataset you would like to download by clicking on the checkbox on the left of the dataset name. See the video below.\n",
"After you download the dataset zip file, make sure you unzip/extract the contents in the appropriate location.\n",
"\n",
"**This notebook assumes that you have downloaded `ellipsoid-v1` and you have placed the unzipped folder `ellipsoid-v1` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"**This notebook assumes that you have downloaded `ellipsoid_1mode` and you have placed the unzipped folder `ellipsoid_1mode` in `Examples/Python/Data`.** Feel free to use your own dataset. \n",
"\n",
"\n",
"<p><video src=\"https://sci.utah.edu/~shapeworks/doc-resources/mp4s/portal_data_download.mp4\" autoplay muted loop controls style=\"width:100%\"></p>\n"
Expand All @@ -145,7 +145,7 @@
"import os # for paths and mkdir\n",
"\n",
"# dataset name is the folder name for your dataset\n",
"datasetName = 'ellipsoid-v1'\n",
"datasetName = 'ellipsoid_1mode'\n",
"\n",
"# path to the dataset where we can find shape data \n",
"# here we assume shape data are given as binary segmentations\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,20 @@
" Datatype : `bool` <br> \n",
" Defaut value : `True` <br>\n",
" <br> \n",
"- `randomize_rotation`: randomizes the orientation of the ellispoids if set to `True` <br>\n",
"- `randomize_rotation`: randomizes the orientation of the ellipsoid if set to `True` <br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
" \n",
"- `randomize_x_radius`: randomizes the radius of the ellipsoid along x-axis if set to `True` or else the value is fixed as 20 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
"- `randomize_y_radius`: randomizes the radius of the ellipsoid along y-axis if set to `True` or else the value is fixed as 10 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
"- `randomize_z_radius`: randomizes the radius of the ellipsoid along z-axis if set to `True` or else the value is fixed as 10 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>"
Expand Down Expand Up @@ -610,6 +623,7 @@
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
" \n",
"- `spacing`: set the spacing of the segmentation image <br>\n",
" Datatype: `list` <br>\n",
" Default value: `[1,1,1]` <br>\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def generate_images(self, blur_factor=1, foreground_mean=180, foreground_var=30,
class EllipsoidCohortGenerator(CohortGenerator):
def __init__(self,out_dir):
super().__init__(out_dir)
def generate(self, num_samples=3, randomize_center=True, randomize_rotation=True):
self.meshes = Ellipsoids.generate(num_samples, self.out_dir, randomize_center, randomize_rotation)
def generate(self, num_samples=3, randomize_center=True, randomize_rotation=True, randomize_x_radius=True, randomize_y_radius=True, randomize_z_radius=True):
self.meshes = Ellipsoids.generate(num_samples, self.out_dir, randomize_center, randomize_rotation, randomize_x_radius, randomize_y_radius, randomize_z_radius)
return self.meshes

class SupershapesCohortGenerator(CohortGenerator):
Expand Down
24 changes: 16 additions & 8 deletions Python/ShapeCohortGenPackage/ShapeCohortGen/Ellipsoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,26 @@ def addEllipsoid(center, radii, rotation, resolution=24):

return translateFilter

def generate_ellipsoids(filename, meshDir, randomize_center, randomize_rotation):
def generate_ellipsoids(filename, meshDir, randomize_center, randomize_rotation, randomize_x_radius, randomize_y_radius, randomize_z_radius):
vtkFileName = meshDir+"ellipsoid_"+filename+".vtk"
plyFileName = meshDir+"ellipsoid_"+filename+".ply"
if randomize_center:
center_loc = list(np.random.randint(low = 0,high=50,size=3))
else:
center_loc = [0,0,0]
x_radius = np.random.randint(low =15,high=25,size =1)
y_radius = np.random.randint(low =5,high=15,size =1)
z_radius = np.random.randint(low =5,high=15,size =1)

radii = [x_radius[0],y_radius[0],z_radius[0]]
if randomize_x_radius:
x_radius = np.random.randint(low =15,high=25,size =1)[0]
else:
x_radius = 20
if randomize_y_radius:
y_radius = np.random.randint(low =5,high=15,size =1)[0]
else:
y_radius = 10
if randomize_z_radius:
z_radius = np.random.randint(low =5,high=15,size =1)[0]
else:
z_radius = 12
radii = [x_radius,y_radius,z_radius]
if randomize_rotation:
rotation = np.random.randint(low=0,high=180,size=1)[0]
else:
Expand All @@ -64,10 +72,10 @@ def generate_ellipsoids(filename, meshDir, randomize_center, randomize_rotation)
vtk_writer.Update()


def generate(num_samples,out_dir,randomize_center, randomize_rotation):
def generate(num_samples,out_dir,randomize_center, randomize_rotation, randomize_x_radius, randomize_y_radius, randomize_z_radius):
meshDir = out_dir + "meshes/"
make_dir(meshDir)
for i in range(num_samples):
filename = str(i).zfill(2)
generate_ellipsoids(filename, meshDir, randomize_center, randomize_rotation)
generate_ellipsoids(filename, meshDir, randomize_center, randomize_rotation, randomize_x_radius, randomize_y_radius, randomize_z_radius)
return get_files(meshDir)
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,20 @@
" Datatype : `bool` <br> \n",
" Defaut value : `True` <br>\n",
" <br> \n",
"- `randomize_rotation`: randomizes the orientation of the ellispoids if set to `True` <br>\n",
"- `randomize_rotation`: randomizes the orientation of the ellipsoid if set to `True` <br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
" \n",
"- `randomize_x_radius`: randomizes the radius of the ellipsoid along x-axis if set to `True` or else the value is fixed as 20 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
"- `randomize_y_radius`: randomizes the radius of the ellipsoid along y-axis if set to `True` or else the value is fixed as 10 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
"- `randomize_z_radius`: randomizes the radius of the ellipsoid along z-axis if set to `True` or else the value is fixed as 10 for all ellipsoids<br>\n",
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>"
Expand Down Expand Up @@ -610,6 +623,7 @@
" Datatype : `bool` <br> \n",
" Defaut value : `True`\n",
" <br>\n",
" \n",
"- `spacing`: set the spacing of the segmentation image <br>\n",
" Datatype: `list` <br>\n",
" Default value: `[1,1,1]` <br>\n",
Expand Down