-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageColorisation.py
58 lines (50 loc) · 1.24 KB
/
imageColorisation.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
import pylab as pl
from colorSpace import *
import numpy as np
import math
from skimage import img_as_float
from getColorExact import getColorExact
inputFile = 'example.bmp'
markedFile = 'example_m.bmp'
outputFile = 'example_rp.bmp'
gI = img_as_float(pl.imread(inputFile))
cI = img_as_float(pl.imread(markedFile))
print gI[113:120,112:120,1]
colorIm = np.abs(gI-cI)
colorIm = colorIm.sum(axis=2)
colorIm = colorIm>0.01
colorIm = colorIm.astype(float)
print "colorIm.shape=\n"
print colorIm.shape
print colorIm[113:120,112:120]
sgI = rgb2ntsc(gI)
scI = rgb2ntsc(cI)
pl.imshow(scI)
pl.show()
'''
ntscIm = np.zeros(np.shape(sgI),float)
ntscIm[:,:,0] = sgI[:,:,0]
ntscIm[:,:,1] = scI[:,:,1]
ntscIm[:,:,2] = scI[:,:,2]
max_d = math.floor(math.log(min(np.size(ntscIm,0),np.size(ntscIm,1)))/math.log(2)-2)
iu = math.floor(np.size(ntscIm,0)/(2**(max_d-1)))*(2**(max_d-1))
ju = math.floor(np.size(ntscIm,1)/(2**(max_d-1)))*(2**(max_d-1))
id = 0
jd = 0
print "max_d=\n"
print max_d
print "iu=\n"
print iu
print "ju=\n"
print ju
colorIm = colorIm[id:iu+1,jd:ju+1]
#pl.imshow(colorIm,origin='lower')
#pl.show()
print colorIm.shape
ntscIm = ntscIm[id:iu,jd:ju,:]
#pl.imshow(colorIm,origin='lower')
#pl.show()
nI = getColorExact(colorIm,ntscIm)
pl.imshow(nI)
pl.show()
'''