forked from mehrtash/Prostate-Segmenter
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfit.py
More file actions
57 lines (51 loc) · 2.04 KB
/
fit.py
File metadata and controls
57 lines (51 loc) · 2.04 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import print_function, absolute_import, division
# Silence warnings
import warnings
warnings.simplefilter(action="ignore", category=FutureWarning)
warnings.simplefilter(action="ignore", category=UserWarning)
warnings.simplefilter(action="ignore", category=RuntimeWarning)
warnings.simplefilter(action='ignore', category=DeprecationWarning)
import getopt
import os
import sys
SEGMENTER_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'boneseg')
print(SEGMENTER_PATH)
sys.path.insert(1, SEGMENTER_PATH)
from boneseg.model import CNNModel
from boneseg.nets import unet1
from boneseg.segmenter import Segmenter
def main(argv):
InputVolume = ''
OutputLabel = ''
try:
opts, args = getopt.getopt(argv, "hi:o:", ["InputVolume=", "OutputLabel="])
except getopt.GetoptError:
print('usage: fit.py -InputVolume <InputVolumePath> --OutputLabel <OutputLabelPath>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('fit.py -InputVolume <InputVolumePath> --OutputLabel <OutputLabelPath>')
sys.exit()
elif opt in ("-i", "--InputVolume"):
InputVolume = arg
elif opt in ("-o", "--OutputLabel"):
OutputLabel = arg
if InputVolume == '' or OutputLabel == '':
print('usage: fit.py -InputVolume <InputVolumePath> -OutputLabel <OutputLabelPath>')
sys.exit()
if os.path.isfile(InputVolume) and os.path.isdir(os.path.dirname(OutputLabel)):
print("Building the model.")
model = unet1.model(weights=True, summary=False)
cnn = CNNModel(model=model, mean_val = 127, max_val = 127)
rows = 128
cols = 128
#
print("Resizing images and segmenting")
sg = Segmenter(cnn)
sg.segment_bone_volume(InputVolume, OutputLabel, rows, cols)
else:
print("Make sure the input file exists and the output file directory is valid.")
print("InputVolume: ", InputVolume)
print("OutputLabel: ", OutputLabel)
if __name__ == "__main__":
main(sys.argv[1:])