-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
44 lines (40 loc) · 1.61 KB
/
utils.py
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
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from copy import deepcopy
def gen_cmap(N=10000):
return matplotlib.colors.LinearSegmentedColormap.from_list("", [(0,'black'), (0.06,'blue'),
(0.23, '#2ab6c6'), (0.38,'yellow'),
(0.6,'red'), (1,'white')], N=N)
def plot_2dmap(img, with_ref=False, ref_img=None, delartifact=False, cm=None):
if cm == None:
cm = gen_cmap(256)
img_copy2d = deepcopy(img)
# mark the rim and cup regions by -1 and -2 locations
if show_cup:
img_copy2d[img_copy2d==-1] = np.nan
cm.set_bad("gray")
cm.set_under(color='lightgray')
# mark rim and cup regions from reference img
if with_ref:
img_copy2d[ref_img==-2] = -2
img_copy2d[ref_img==-1] = np.nan
cm.set_bad(color="gray")
cm.set_under(color='lightgray')
# delete artifact locations defined by <=30 and >=0
if delartifact:
img_copy2d[(img_copy2d<=30) & (img_copy2d>0)] = 0
fig = plt.figure()
ax = plt.subplot(111)
img_copy2d = ax.imshow(img_copy2d, cmap=cm, vmin=-0.00000001, vmax=350)
if show_colorbar:
cbar = plt.colorbar(img_copy2d, pad=0.01, aspect=12, location='left')
cbar.set_ticks([0, 175,350])
cbar.ax.set_yticklabels(['0 μm', '175 μm', '350 μm'])
cbar.ax.tick_params(labelsize=14)
if title_on:
ax.set_title('RNFL Thickness Map', fontsize=15)
ax.axis('off')
else:
ax.axis('off')
plt.show()