-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathimage_utils.py
More file actions
22 lines (18 loc) · 761 Bytes
/
image_utils.py
File metadata and controls
22 lines (18 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
import cv2
def show_cam_on_image(img, mask, neg_saliency=False):
heatmap = cv2.applyColorMap(np.uint8(255 * mask), cv2.COLORMAP_JET)
heatmap = np.float32(heatmap) / 255
cam = heatmap + np.float32(img)
cam = cam / np.max(cam)
return cam
def show_overlapped_cam(img, neg_mask, pos_mask):
neg_heatmap = cv2.applyColorMap(np.uint8(255 * neg_mask), cv2.COLORMAP_RAINBOW)
pos_heatmap = cv2.applyColorMap(np.uint8(255 * pos_mask), cv2.COLORMAP_JET)
neg_heatmap = np.float32(neg_heatmap) / 255
pos_heatmap = np.float32(pos_heatmap) / 255
# try different options: sum, average, ...
heatmap = neg_heatmap + pos_heatmap
cam = heatmap + np.float32(img)
cam = cam / np.max(cam)
return cam