forked from imlab-uiip/lung-segmentation-2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_JSRT.py
22 lines (19 loc) · 858 Bytes
/
preprocess_JSRT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import numpy as np
from skimage import io, exposure
def make_lungs():
path = '/path/to/JSRT/All247images/'
for i, filename in enumerate(os.listdir(path)):
img = 1.0 - np.fromfile(path + filename, dtype='>u2').reshape((2048, 2048)) * 1. / 4096
img = exposure.equalize_hist(img)
io.imsave('/path/to/JSRT/new/' + filename[:-4] + '.png', img)
print 'Lung', i, filename
def make_masks():
path = '/path/to/JSRT/All247images/'
for i, filename in enumerate(os.listdir(path)):
left = io.imread('/path/to/JSRT/Masks/left lung/' + filename[:-4] + '.gif')
right = io.imread('/path/to/JSRT/Masks/right lung/' + filename[:-4] + '.gif')
io.imsave('/path/to/JSRT/new/' + filename[:-4] + 'msk.png', np.clip(left + right, 0, 255))
print 'Mask', i, filename
make_lungs()
make_masks()