Switch to unified view

a b/1 - Methods with Improved Results/ModelFunctions.py
1
from SegmentationFunctions import *
2
3
def modelPipeline(img_path):
4
    
5
    ID = img_path[img_path.find('/') + 1 : img_path.find('_')]
6
    sliceNo = img_path[img_path.find('_') + 1 : img_path.find('.')]
7
    
8
    print('\t******* SEGMENTATION PIPELINE ********')
9
    print('Patient:', ID + ', Slice Number:', sliceNo)
10
    
11
    im = readImg(img_path, showOutput=0)
12
    
13
    procImg, fg_threshold = preprocessImage(im, showOutput=0)
14
    print('...preprocessing')
15
    
16
    fg_mask = getForegroundMask(procImg, fg_threshold, showOutput=0)
17
    print('...computing foreground mask')
18
    
19
    trachea_mask, lung_mask, ch_lung_mask, int_heart_mask = getLungTracheaMasks(procImg, 
20
                                                                          fg_mask, 
21
                                                                          fg_threshold, 
22
                                                                          showOutput=0)
23
    print('...computing lung mask')
24
    
25
    spine_mask, heart_mask = chullSpineMask(im, int_heart_mask, showOutput=0)
26
    print('...computing spine & heart masks')
27
    
28
    segmented_heart, segmented_lungs, segmented_trachea = segmentHeartLungsTrachea(im, 
29
                                                                               heart_mask, 
30
                                                                               lung_mask, 
31
                                                                               trachea_mask, 
32
                                                                               showOutput=0)
33
    
34
    heart_colored, lung_colored, trachea_colored, colored_masks = getColoredMasks(im, 
35
                                                                                  heart_mask, 
36
                                                                                  lung_mask, 
37
                                                                                  trachea_mask,
38
                                                                                  showOutput=1)
39
40
slices, PatientID = readSortedSlices('sample-dataset')
41
42
for slicePath in slices:    
43
    modelPipeline(slicePath)