|
a |
|
b/segment_airway.py |
|
|
1 |
import numpy as np |
|
|
2 |
import nibabel as nib |
|
|
3 |
from scipy import ndimage |
|
|
4 |
from utils import * |
|
|
5 |
|
|
|
6 |
def segment_airway(params, I, I_affine, Mlung): |
|
|
7 |
|
|
|
8 |
##################################################### |
|
|
9 |
# Initialize parameters |
|
|
10 |
##################################################### |
|
|
11 |
|
|
|
12 |
Radius = params['airwayRadiusMask'] |
|
|
13 |
RadiusX = params['airwayRadiusX'] |
|
|
14 |
RadiusZ = params['airwayRadiusZ'] |
|
|
15 |
struct_s = ndimage.generate_binary_structure(3, 1) |
|
|
16 |
struct_l = ndimage.iterate_structure(struct_s, 3) |
|
|
17 |
struct_trachea = generate_structure_trachea(Radius, RadiusX, RadiusZ) |
|
|
18 |
|
|
|
19 |
##################################################### |
|
|
20 |
# Locate an inital point in trachea |
|
|
21 |
##################################################### |
|
|
22 |
|
|
|
23 |
slice_no, initLoc = generate_initLoc(params, I, Mlung, Radius, RadiusZ, struct_trachea) |
|
|
24 |
|
|
|
25 |
##################################################### |
|
|
26 |
# Find airway with closed space diallation |
|
|
27 |
##################################################### |
|
|
28 |
|
|
|
29 |
Maw = close_space_dilation(params, I, Mlung, Radius, RadiusX, RadiusZ, struct_s, slice_no, initLoc) |
|
|
30 |
|
|
|
31 |
##################################################### |
|
|
32 |
# Remove airway & save nii |
|
|
33 |
##################################################### |
|
|
34 |
|
|
|
35 |
Mawtmp = ndimage.binary_dilation(Maw, structure = struct_l, iterations = 1) |
|
|
36 |
Mawtmp = np.int8(Mawtmp) |
|
|
37 |
Mlung[Maw > 0] = 0 |
|
|
38 |
nib.Nifti1Image(Maw,I_affine).to_filename('./result/sample_aw.nii.gz') |
|
|
39 |
nib.Nifti1Image(Mlung,I_affine).to_filename('./result/sample_lung.nii.gz') |
|
|
40 |
|
|
|
41 |
return Mlung, Maw |
|
|
42 |
|