forked from CRBS/PyIMOD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImodGen.py
81 lines (68 loc) · 2.73 KB
/
ImodGen.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from .ImodModel import ImodModel
from .ImodObject import ImodObject
from .ImodWrite import ImodWrite
from .utils import ImodCmd
def blankTrainingModel(filename = None):
"""
Creates a blank model file to be used for generating CHM training images
and labels using IMOD. The output model file can be loaded on any MRC
file, regardless of size or offsets.
"""
# Create ImodModel class and two ImodObject sub-classes
model = ImodModel()
model.addObject()
model.addObject()
# Set object properties of Object 1 (seed points)
model.Objects[0].setName('Seed Points')
model.Objects[0].setColor(0, 1, 0)
model.Objects[0].setObjectType('scattered')
model.Objects[0].setSymbolType('circle')
model.Objects[0].setSymbolSize(10)
model.Objects[0].setSymbolFillOn()
# Set object properties of Object 2 (training contours)
model.Objects[1].setName('Training Contours')
model.Objects[1].setColor(0, 1, 1)
model.Objects[1].setObjectType('closed')
model.Objects[1].setLineWidth(2)
# Write or return file
if filename:
ImodWrite(model, filename)
else:
return model
def tutorialModel(filename = None):
"""
Creates a model file used in pyimod tutorials. Model file containts 25
objects consisting of spheres and cubes of various sizes and positions.
"""
model = ImodModel()
model.setImageSize(1000, 1000, 1000)
model.setPixelSizeXY(4)
model.setPixelSizeZ(4)
model.setUnits('nm')
# Make big central sphere
model.genSphereObject([500, 500, 500], 200, 100)
# Make small, radius 50 spheres at 10 defined locations
centers = [[700, 700, 700], [700, 800, 400], [300, 300, 500],
[450, 300, 100], [100, 100, 100], [850, 200, 600], [400, 700, 300],
[800, 100, 700], [200, 900, 400]]
[model.genSphereObject(x, 50, 25) for x in centers]
# Make medium, radius 100 spheres at 10 defined locations
centers = [[200, 200, 400], [150, 750, 800], [900, 500, 500],
[800, 350, 350], [500, 100, 100]]
[model.genSphereObject(x, 100, 50) for x in centers]
# Make small, width 50 cubes at 5 defined locations
centers = [[150, 500, 500], [850, 900, 850], [700, 200, 200],
[850, 150, 800], [500, 500, 800]]
[model.genCubeObject(x, 50) for x in centers]
# Make medium, width 100 cubes at 5 defined locations
centers = [[450, 850, 700], [800, 500, 850], [150, 500, 250],
[750, 800, 200], [250, 200, 800]]
[model.genCubeObject(x, 100) for x in centers]
# Mesh all objects, with capping turned on
model = ImodCmd(model, 'imodmesh -C')
# Set line widths to 3
model.setAll(linewidth = 3)
if filename:
ImodWrite(model, filename)
else:
return model