-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (32 loc) · 1.34 KB
/
Copy pathutils.py
File metadata and controls
36 lines (32 loc) · 1.34 KB
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
from skimage import feature, transform
import numpy as np
import matplotlib.pyplot as plt
def plot(data, xi=None, cmap='RdBu_r', axis=plt, percentile=100, dilation=3.0, alpha=0.8):
dx, dy = 0.05, 0.05
xx = np.arange(0.0, data.shape[1], dx)
yy = np.arange(0.0, data.shape[0], dy)
xmin, xmax, ymin, ymax = np.amin(xx), np.amax(xx), np.amin(yy), np.amax(yy)
extent = xmin, xmax, ymin, ymax
cmap_xi = plt.get_cmap('Greys_r')
cmap_xi.set_bad(alpha=0)
overlay = None
if xi is not None:
# Compute edges (to overlay to heatmaps later)
xi_greyscale = xi if len(xi.shape) == 2 else np.mean(xi, axis=-1)
in_image_upscaled = transform.rescale(xi_greyscale, dilation, mode='constant')
edges = feature.canny(in_image_upscaled).astype(float)
edges[edges < 0.5] = np.nan
edges[:5, :] = np.nan
edges[-5:, :] = np.nan
edges[:, :5] = np.nan
edges[:, -5:] = np.nan
overlay = edges
abs_max = np.percentile(np.abs(data), percentile)
abs_min = abs_max
if len(data.shape) == 3:
data = np.mean(data, 2)
axis.imshow(data, extent=extent, interpolation='none', cmap=cmap, vmin=-abs_min, vmax=abs_max)
if overlay is not None:
axis.imshow(overlay, extent=extent, interpolation='none', cmap=cmap_xi, alpha=alpha)
axis.axis('off')
return axis