-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils_openset.py
137 lines (102 loc) · 3.91 KB
/
utils_openset.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 7 14:56:22 2020
@author: sj
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import rscls
colors = ['#000000','#CACACA', '#02FF00', '#00FFFF', '#088505', '#FF00FE', '#AA562E', '#8C0085', '#FD0000', '#FFFF00']
cmap = ListedColormap(colors)
#0000FF, #228B22, #7BFC00, #FF0000, #724A12, #C0C0C0, #00FFFF, #FF8000, #FFFF00
def save_cmap_hk(img, cmap, fname):
colors = ['#000000','#008000','#808080','#FFF700','#0290DE','#EDC9Af','#F3F2E7']
cmap = ListedColormap(colors)
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img, cmap=cmap, vmin=0, vmax=6)
plt.savefig(fname, dpi = height)
plt.close()
def save_cmap_pc(img, cmap, fname):
colors = ['#000000','#0000FF','#228B22','#7BFC00', '#FF0000', '#724A12', '#C0C0C0',
'#00FFFF', '#FF8000', '#FFFF00']
cmap = ListedColormap(colors)
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img, cmap=cmap, vmin=0, vmax=9)
plt.savefig(fname, dpi = height)
plt.close()
def save_cmap_salinas16(img,cmap,fname):
colors = ['#000000','#DCB809','#03009A','#FE0000','#FF349B','#FF66FF',
'#0000FD','#EC8101','#00FF00','#838300','#990099','#00F7F1',
'#009999','#009900','#8A5E2D','#67FECB','#F6EF00']
cmap = ListedColormap(colors)
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img, cmap=cmap, vmin=0, vmax=16)
plt.savefig(fname, dpi = height)
plt.close()
def save_cmap_indian16(img,cmap,fname):
colors = ['#000000','#FFFC86','#0037F3','#FF5D00','#00FB84','#FF3AFC',
'#4A32FF','#00ADFF','#00FA00','#AEAD51','#A2549E','#54B0FF',
'#375B70','#65BD3C','#8F462C','#6CFCAB','#FFFC00']
cmap = ListedColormap(colors)
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img, cmap=cmap, vmin=0, vmax=16)
plt.savefig(fname, dpi = height)
plt.close()
def save_cmap_pu9(img, cmap, fname):
colors = ['#000000','#CACACA','#02FF00','#00FFFF','#088505','#FF00FE','#AA562E','#8C0085','#FD0000', '#FFFF00']
cmap = ListedColormap(colors)
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img, cmap=cmap, vmin=0, vmax=9)
plt.savefig(fname, dpi = height)
plt.close()
def save_im(img,fname):
sizes = np.shape(img)
height = float(sizes[0])
width = float(sizes[1])
fig = plt.figure()
fig.set_size_inches(width/height, 1, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img)
plt.savefig(fname, dpi = height)
plt.close()
#save_im(rscls.strimg255(im[:,:,[50,34,20]],5),'indian_im')
#plt.imshow(rscls.strimg255(im[:,:,[50,34,20]],5))
#save_cmap(pre1,cmap,'a')