-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotting_utils.py
39 lines (28 loc) · 1.19 KB
/
plotting_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
"""
Plotting utilities for example notebooks
"""
import matplotlib.pyplot as plt
import numpy as np
def plot_image(image=None, mask=None, ax=None, factor=3.5/255, clip_range=(0, 1), **kwargs):
""" Utility function for plotting RGB images and masks.
"""
if ax is None:
_, ax = plt.subplots(nrows=1, ncols=1, figsize=(15, 15))
mask_color = [255, 255, 255, 255] if image is None else [255, 255, 0, 100]
if image is None:
if mask is None:
raise ValueError('image or mask should be given')
image = np.zeros(mask.shape + (3,), dtype=np.uint8)
ax.imshow(np.clip(image * factor, *clip_range), **kwargs)
if mask is not None:
cloud_image = np.zeros((mask.shape[0], mask.shape[1], 4), dtype=np.uint8)
cloud_image[mask == 1] = np.asarray(mask_color, dtype=np.uint8)
ax.imshow(cloud_image)
def plot_probabilities(image, proba, factor=3.5/255):
""" Utility function for plotting a RGB image and its cloud probability map next to each other.
"""
plt.figure(figsize=(15, 15))
ax = plt.subplot(1, 2, 1)
ax.imshow(np.clip(image * factor, 0, 1))
ax = plt.subplot(1, 2, 2)
ax.imshow(proba, cmap=plt.cm.inferno)