forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
convertLabelColours.py
executable file
·70 lines (55 loc) · 1.37 KB
/
convertLabelColours.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
#!/usr/bin/env python
import sys
import skimage.io
import numpy as np
import matplotlib.pyplot as plt
import pomio
# usage:
#
# convertLabelColours.py inputFn.png outputFn.png
#
#
# Colour map, from-to
#
cmap = [\
( ( 0,255, 0),( 0,128, 0) ), \
( (200,100, 20),(128,128, 0) ), \
( (255, 0, 0),(128, 0, 0) ), \
( ( 0, 0,255),( 64,128, 0) ), \
( (100,100,100),(128, 64,128) ), \
]
infile = sys.argv[1]
outfile= sys.argv[2]
image = skimage.io.imread(infile)
plt.interactive(1)
plt.figure()
pomio.showClassColours()
plt.figure()
plt.imshow(image)
plt.title('input labels')
#plt.waitforbuttonpress()
# Make the output image
newimg = image.copy()
# for each colour make the transfer
nc = 3 # number colour channels
for cpair in cmap:
clrFrom = cpair[0]
clrTo = cpair[1]
print 'Mapping ', clrFrom, ' to ', clrTo
# find the from pixels
msk = np.logical_and( image[:,:,0] == clrFrom[0], np.logical_and( image[:,:,1] == clrFrom[1], \
image[:,:,2] == clrFrom[2] ) )
if 0:
plt.clf()
plt.imshow(msk)
plt.set_cmap( 'gray' )
plt.waitforbuttonpress()
for c in range(nc):
plane = newimg[:,:,c]
plane[msk] = clrTo[c]
# write the output image
skimage.io.imsave(outfile,newimg)
plt.figure()
plt.imshow(newimg)
plt.title('output labels')
plt.waitforbuttonpress()