-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunReal.py
More file actions
34 lines (33 loc) · 757 Bytes
/
runReal.py
File metadata and controls
34 lines (33 loc) · 757 Bytes
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
import numpy as np
from runIm import runIm
def runReal(I):
m,n=I.shape
R=np.zeros_like(I)
block=2**int(np.floor(np.log2(min(I.shape))))+1
gap=10
xGrid=getGrid(block,gap,m)
yGrid=getGrid(block,gap,n)
for x0 in xGrid:
for y0 in yGrid:
x0-=1
y0-=1
curI=I[x0:x0+block,y0:y0+block]
curR=runIm(curI)
curR[0:2,:]=0
curR[-2:,:]=0
curR[:,0:2]=0
curR[:,-2:]=0
R[x0:x0+block,y0:y0+block]=np.fmax(R[x0:x0+block,y0:y0+block],curR)
return R
def getGrid(block,gap,maximum):
grid=np.zeros(maximum,dtype=int)
grid[0]=1
for i in range(1,maximum):
grid[i]=grid[i-1]+block-gap
if grid[i]+block-1>maximum:
grid[i]=maximum-block+1
break
grid=grid[grid!=0]
if len(grid)>=2 and grid[-1]==grid[-2]:
grid=grid[:-1]
return grid