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 matplotlib.pyplot as plt import cv2 import numpy as np
demo_img_path = r"res\img\36979.jpg" demo_img = plt.imread(demo_img_path) demo_img_h, demo_img_w, demo_img_c = demo_img.shape
demo_img_att = np.array([ [0.1, 0.4, 0.4, 0, 0], [0, 0.4, 0.4, 0.4, 0], [0.4, 0, 0, 0.3, 0.4], [0.2, 0.1, 0, 0, 0.4], [0.3, 0.4, 0.1, 0, 0], ])
demo_img_att = cv2.resize(demo_img_att, dsize=(demo_img_w, demo_img_h), interpolation=cv2.INTER_CUBIC)
plt.figure(figsize=(9, 5))
plt.subplot(1, 2, 1) plt.imshow(demo_img) plt.axis("off") plt.title("image")
plt.subplot(1, 2, 2) plt.imshow(demo_img) plt.imshow(demo_img_att, alpha=0.8, cmap="gray") plt.axis("off") plt.title("image with attention")
plt.tight_layout()
plt.savefig("demo_img_att.png") plt.show()
|