-
Notifications
You must be signed in to change notification settings - Fork 3
/
mosaic.pyx
76 lines (67 loc) · 2.09 KB
/
mosaic.pyx
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
import numpy as np
cimport numpy as np
cimport cython
np.import_array()
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def idxarr(float [:,:] src):
cdef int x, y, xsize, ysize
cdef int c = 1
xsize = src.shape[1]
ysize = src.shape[0]
ididx = np.zeros((src.shape[0], src.shape[1]), dtype=np.int)
for x in range(xsize):
for y in range(ysize):
if src[y, x] != 0:
ididx[y, x] = c
c += 1
return ididx, c
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
def genAb(float [:,:] src,
float [:,:] srclap,
long [:,:] imidx,
float [:,:] dest,
int n):
"""
This is a gigantic laplacian filter the the destination image
"""
cdef int count, x, y, xsize, ysize, colidx
xsize = src.shape[1]
ysize = src.shape[0]
A = np.empty((n,n))
b = np.zeros(n, dtype=np.float64)
sol = np.zeros(n, dtype=np.float64)
print n, xsize * ysize
count = 1
print "Generating A and b"
for x in range(1, xsize-1):
for y in range(1, ysize-1):
if src[y,x] != 0.0:
#Upper pixel
if src[y-1, x] != 0:
colidx = imidx[y - 1, x]
A[count, colidx] = -1
else:
b[count] = b[count] + dest[y-1, x]
if src[y, x-1] != 0:
colidx = imidx[y, x - 1]
A[count, colidx] = -1
else:
b[count] = b[count] + dest[y, x-1]
if src[y+1, x] != 0:
colidx = imidx[y+1, x]
A[count, colidx] = -1
else:
b[count] = b[count] + dest[y+1, x]
if src[y, x+1] != 0:
colidx = imidx[y, x + 1]
A[count, colidx] = -1
else:
b[count] = b[count] + dest[y, x+1]
A[count, count] = 4
b[count] = b[count] + srclap[y,x]
count += 1
return A, b