-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmap_2_jpg.py
51 lines (40 loc) · 1.5 KB
/
pmap_2_jpg.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
45
46
47
48
49
50
import cv2
import matplotlib.pyplot as plt
import numpy as np
import os
import h5py
import scipy.io as sio
from PIL import Image
def pmap_mat_jpg(mat_path, set_xy=False):
# Shanghai Tech A train + Shanghai Tech B train / test
mat = h5py.File(mat_path, 'r')
pmap = np.transpose(mat['pmap'])
# Shanghai Tech A test
# mat = sio.loadmat(mat_path)
# pmap = mat['pmap']
if not set_xy:
# plt.xticks([])
# plt.yticks([])
plt.axis('off')
plt.imshow(pmap, cmap=plt.cm.jet)
# save image
plt.savefig(mat_path.replace('perspective_map', 'pmap_imgs').replace('.mat', '.jpg'))
plt.pause(0.2)
plt.close()
if __name__ == '__main__':
# ShangTechA 透视图的mat格式转换为jpg,并保存图片
mat_dir = r'E:\Crowd Counting\data\part_A_final\train_data\perspective_map'
# mat_dir = r'E:\Crowd Counting\data\part_A_final\test_data\perspective_map'
mat_paths = os.listdir(mat_dir)
for mat_path in mat_paths:
if '.mat' in mat_path:
pmap_mat_jpg(os.path.join(mat_dir, mat_path), set_xy=False)
plt.show()
# ShangTechB 透视图的mat格式转换为jpg,并保存图片
# mat_dir = r'E:\Crowd Counting\data\part_B_final\train_data\perspective_map'
# mat_dir = r'E:\Crowd Counting\data\part_B_final\test_data\perspective_map'
# mat_paths = os.listdir(mat_dir)
# for mat_path in mat_paths:
# if '.mat' in mat_path:
# pmap_mat_jpg(os.path.join(mat_dir, mat_path), set_xy=False)
# plt.show()