farrell236 commited on
Commit
39b990a
1 Parent(s): 8b04a58

adding original files

Browse files
DL_info.csv ADDED
The diff for this file is too large to render. See raw diff
 
changelog.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [07/20/2018] First release of DeepLesion.
2
+ [07/27/2018] We re-zipped the images and replaced the old zips in Images_png. The files in old and new zips are the same in total except that every new zip file contains several independent folders and can be unzipped alone. Readme and FAQ are updated. We also added a folder "Key_slice_examples" to help users understand the dataset at a glance.
3
+ [07/30/2018] The link to our GitHub page is added in readme, which includes a project showing how to train a lesion detector using DeepLesion.
4
+ [09/05/2018] batch_download_zips.py is added to download all 56 zip files automatically.
5
+ [05/13/2019] Address of the semantic labels (tags) for the lesions is addeed in readme and FAQ.
scripts/DL_save_nifti.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """
3
+ Ke Yan
4
+ Imaging Biomarkers and Computer-Aided Diagnosis Laboratory
5
+ National Institutes of Health Clinical Center
6
+ May 2018
7
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
8
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
10
+ IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
11
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
12
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
16
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
+ """
18
+
19
+ """
20
+ A simple demo to load 2D 16-bit slices from DeepLesion and save to 3D nifti volumes.
21
+ The nifti volumes can be viewed in software such as 3D slicer and ITK-SNAP.
22
+ """
23
+
24
+
25
+ import numpy as np
26
+ import nibabel as nib
27
+ import os
28
+ import cv2
29
+ import csv
30
+
31
+
32
+ dir_in = 'Images_png'
33
+ dir_out = 'Images_nifti'
34
+ out_fmt = '%s_%03d-%03d.nii.gz' # format of the nifti file name to output
35
+ info_fn = 'DL_info.csv' # file name of the information file
36
+
37
+
38
+ def slices2nifti(ims, fn_out, spacing):
39
+ """save 2D slices to 3D nifti file considering the spacing"""
40
+ if len(ims) < 300: # cv2.merge does not support too many channels
41
+ V = cv2.merge(ims)
42
+ else:
43
+ V = np.empty((ims[0].shape[0], ims[0].shape[1], len(ims)))
44
+ for i in range(len(ims)):
45
+ V[:, :, i] = ims[i]
46
+
47
+ # the transformation matrix suitable for 3D slicer and ITK-SNAP
48
+ T = np.array([[0, -spacing[1], 0, 0], [-spacing[0], 0, 0, 0], [0, 0, -spacing[2], 0], [0, 0, 0, 1]])
49
+ img = nib.Nifti1Image(V, T)
50
+ path_out = os.path.join(dir_out, fn_out)
51
+ nib.save(img, path_out)
52
+ print fn_out, 'saved'
53
+
54
+
55
+ def load_slices(dir, slice_idxs):
56
+ """load slices from 16-bit png files"""
57
+ slice_idxs = np.array(slice_idxs)
58
+ assert np.all(slice_idxs[1:] - slice_idxs[:-1] == 1)
59
+ ims = []
60
+ for slice_idx in slice_idxs:
61
+ fn = '%03d.png' % slice_idx
62
+ path = os.path.join(dir_in, dir, fn)
63
+ im = cv2.imread(path, -1) # -1 is needed for 16-bit image
64
+ assert im is not None, 'error reading %s' % path
65
+ print 'read', path
66
+
67
+ # the 16-bit png file has a intensity bias of 32768
68
+ ims.append((im.astype(np.int32) - 32768).astype(np.int16))
69
+ return ims
70
+
71
+
72
+ def read_DL_info():
73
+ """read spacings and image indices in DeepLesion"""
74
+ spacings = []
75
+ idxs = []
76
+ with open(info_fn, 'rb') as csvfile:
77
+ reader = csv.reader(csvfile)
78
+ rownum = 0
79
+ for row in reader:
80
+ if rownum == 0:
81
+ header = row
82
+ rownum += 1
83
+ else:
84
+ idxs.append([int(d) for d in row[1:4]])
85
+ spacings.append([float(d) for d in row[12].split(',')])
86
+
87
+ idxs = np.array(idxs)
88
+ spacings = np.array(spacings)
89
+ return idxs, spacings
90
+
91
+
92
+ if __name__ == '__main__':
93
+ idxs, spacings = read_DL_info()
94
+ if not os.path.exists(dir_out):
95
+ os.mkdir(dir_out)
96
+ img_dirs = os.listdir(dir_in)
97
+ img_dirs.sort()
98
+ for dir1 in img_dirs:
99
+ # find the image info according to the folder's name
100
+ idxs1 = np.array([int(d) for d in dir1.split('_')])
101
+ i1 = np.where(np.all(idxs == idxs1, axis=1))[0]
102
+ spacings1 = spacings[i1[0]]
103
+
104
+ fns = os.listdir(os.path.join(dir_in, dir1))
105
+ slices = [int(d[:-4]) for d in fns if d.endswith('.png')]
106
+ slices.sort()
107
+
108
+ # Each folder contains png slices from one series (volume)
109
+ # There may be several sub-volumes in each volume depending on the key slices
110
+ # We group the slices into sub-volumes according to continuity of the slice indices
111
+ groups = []
112
+ for slice_idx in slices:
113
+ if len(groups) != 0 and slice_idx == groups[-1][-1]+1:
114
+ groups[-1].append(slice_idx)
115
+ else:
116
+ groups.append([slice_idx])
117
+
118
+ for group in groups:
119
+ # group contains slices indices of a sub-volume
120
+ ims = load_slices(dir1, group)
121
+ fn_out = out_fmt % (dir1, group[0], group[-1])
122
+ slices2nifti(ims, fn_out, spacings1)
scripts/batch_download_zips.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Download the 56 zip files in Images_png in batches
2
+ import urllib
3
+
4
+ # URLs for the zip files
5
+ links = [
6
+ 'https://nihcc.box.com/shared/static/sp5y2k799v4x1x77f7w1aqp26uyfq7qz.zip',
7
+ 'https://nihcc.box.com/shared/static/l9e1ys5e48qq8s409ua3uv6uwuko0y5c.zip',
8
+ 'https://nihcc.box.com/shared/static/48jotosvbrw0rlke4u88tzadmabcp72r.zip',
9
+ 'https://nihcc.box.com/shared/static/xa3rjr6nzej6yfgzj9z6hf97ljpq1wkm.zip',
10
+ 'https://nihcc.box.com/shared/static/58ix4lxaadjxvjzq4am5ehpzhdvzl7os.zip',
11
+ 'https://nihcc.box.com/shared/static/cfouy1al16n0linxqt504n3macomhdj8.zip',
12
+ 'https://nihcc.box.com/shared/static/z84jjstqfrhhlr7jikwsvcdutl7jnk78.zip',
13
+ 'https://nihcc.box.com/shared/static/6viu9bqirhjjz34xhd1nttcqurez8654.zip',
14
+ 'https://nihcc.box.com/shared/static/9ii2xb6z7869khz9xxrwcx1393a05610.zip',
15
+ 'https://nihcc.box.com/shared/static/2c7y53eees3a3vdls5preayjaf0mc3bn.zip',
16
+
17
+ 'https://nihcc.box.com/shared/static/2zsqpzru46wsp0f99eaag5yiad42iezz.zip',
18
+ 'https://nihcc.box.com/shared/static/8v8kfhgyngceiu6cr4sq1o8yftu8162m.zip',
19
+ 'https://nihcc.box.com/shared/static/jl8ic5cq84e1ijy6z8h52mhnzfqj36q6.zip',
20
+ 'https://nihcc.box.com/shared/static/un990ghdh14hp0k7zm8m4qkqrbc0qfu5.zip',
21
+ 'https://nihcc.box.com/shared/static/kxvbvri827o1ssl7l4ji1fngfe0pbt4p.zip',
22
+ 'https://nihcc.box.com/shared/static/h1jhw1bee3c08pgk537j02q6ue2brxmb.zip',
23
+ 'https://nihcc.box.com/shared/static/78hamrdfzjzevrxqfr95h1jqzdqndi19.zip',
24
+ 'https://nihcc.box.com/shared/static/kca6qlkgejyxtsgjgvyoku3z745wbgkc.zip',
25
+ 'https://nihcc.box.com/shared/static/e8yrtq31g0d8yhjrl6kjplffbsxoc5aw.zip',
26
+ 'https://nihcc.box.com/shared/static/vomu8feie1qembrsfy2yaq36cimvymj8.zip',
27
+
28
+ 'https://nihcc.box.com/shared/static/ecwyyx47p2jd621wt5c5tc92dselz9nx.zip',
29
+ 'https://nihcc.box.com/shared/static/fbnafa8rj00y0b5tq05wld0vbgvxnbpe.zip',
30
+ 'https://nihcc.box.com/shared/static/50v75duviqrhaj1h7a1v3gm6iv9d58en.zip',
31
+ 'https://nihcc.box.com/shared/static/oylbi4bmcnr2o65id2v9rfnqp16l3hp0.zip',
32
+ 'https://nihcc.box.com/shared/static/mw15sn09vriv3f1lrlnh3plz7pxt4hoo.zip',
33
+ 'https://nihcc.box.com/shared/static/zi68hd5o6dajgimnw5fiu7sh63kah5sd.zip',
34
+ 'https://nihcc.box.com/shared/static/3yiszde3vlklv4xoj1m7k0syqo3yy5ec.zip',
35
+ 'https://nihcc.box.com/shared/static/w2v86eshepbix9u3813m70d8zqe735xq.zip',
36
+ 'https://nihcc.box.com/shared/static/0cf5w11yvecfq34sd09qol5atzk1a4ql.zip',
37
+ 'https://nihcc.box.com/shared/static/275en88yybbvzf7hhsbl6d7kghfxfshi.zip',
38
+
39
+ 'https://nihcc.box.com/shared/static/l52tpmmkgjlfa065ow8czhivhu5vx27n.zip',
40
+ 'https://nihcc.box.com/shared/static/p89awvi7nj0yov1l2o9hzi5l3q183lqe.zip',
41
+ 'https://nihcc.box.com/shared/static/or9m7tqbrayvtuppsm4epwsl9rog94o8.zip',
42
+ 'https://nihcc.box.com/shared/static/vuac680472w3r7i859b0ng7fcxf71wev.zip',
43
+ 'https://nihcc.box.com/shared/static/pllix2czjvoykgbd8syzq9gq5wkofps6.zip',
44
+ 'https://nihcc.box.com/shared/static/2dn2kipkkya5zuusll4jlyil3cqzboyk.zip',
45
+ 'https://nihcc.box.com/shared/static/peva7rpx9lww6zgpd0n8olpo3b2n05ft.zip',
46
+ 'https://nihcc.box.com/shared/static/2fda8akx3r3mhkts4v6mg3si7dipr7rg.zip',
47
+ 'https://nihcc.box.com/shared/static/ijd3kwljgpgynfwj0vhj5j5aurzjpwxp.zip',
48
+ 'https://nihcc.box.com/shared/static/nc6rwjixplkc5cx983mng9mwe99j8oa2.zip',
49
+
50
+ 'https://nihcc.box.com/shared/static/rhnfkwctdcb6y92gn7u98pept6qjfaud.zip',
51
+ 'https://nihcc.box.com/shared/static/7315e79xqm72osa4869oqkb2o0wayz6k.zip',
52
+ 'https://nihcc.box.com/shared/static/4nbwf4j9ejhm2ozv8mz3x9jcji6knhhk.zip',
53
+ 'https://nihcc.box.com/shared/static/1lhhx2uc7w14bt70de0bzcja199k62vn.zip',
54
+ 'https://nihcc.box.com/shared/static/guho09wmfnlpmg64npz78m4jg5oxqnbo.zip',
55
+ 'https://nihcc.box.com/shared/static/epu016ga5dh01s9ynlbioyjbi2dua02x.zip',
56
+ 'https://nihcc.box.com/shared/static/b4ebv95vpr55jqghf6bthg92vktocdkg.zip',
57
+ 'https://nihcc.box.com/shared/static/byl9pk2y727wpvk0pju4ls4oomz9du6t.zip',
58
+ 'https://nihcc.box.com/shared/static/kisfbpualo24dhby243nuyfr8bszkqg1.zip',
59
+ 'https://nihcc.box.com/shared/static/rs1s5ouk4l3icu1n6vyf63r2uhmnv6wz.zip',
60
+
61
+ 'https://nihcc.box.com/shared/static/7tvrneuqt4eq4q1d7lj0fnafn15hu9oj.zip',
62
+ 'https://nihcc.box.com/shared/static/gjo530t0dgeci3hizcfdvubr2n3mzmtu.zip',
63
+ 'https://nihcc.box.com/shared/static/7x4pvrdu0lhazj83sdee7nr0zj0s1t0v.zip',
64
+ 'https://nihcc.box.com/shared/static/z7s2zzdtxe696rlo16cqf5pxahpl8dup.zip',
65
+ 'https://nihcc.box.com/shared/static/shr998yp51gf2y5jj7jqxz2ht8lcbril.zip',
66
+ 'https://nihcc.box.com/shared/static/kqg4peb9j53ljhrxe3l3zrj4ac6xogif.zip'
67
+ ]
68
+
69
+ md5_link = 'https://nihcc.box.com/shared/static/q0f8gy79q2spw96hs6o4jjjfsrg17t55.txt'
70
+ urllib.urlretrieve(md5_link, "MD5_checksums.txt") # download the MD5 checksum file
71
+ for idx, link in enumerate(links):
72
+ fn = 'Images_png_%02d.zip' % (idx+1)
73
+ print 'downloading', fn, '...'
74
+ urllib.urlretrieve(link, fn) # download the zip file
75
+ print "Download complete. Please check the MD5 checksums"