-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
52 lines (39 loc) · 1.43 KB
/
functions.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
from math import fabs
import numpy as np
import numba as nb
"""Implementation of different kind of user build-in functions.
"""
@nb.jit
def mean_filter(data,height,width,radius):
mean_logy=np.zeros((height,width))
radius-=1
for i in range(height):
limitUp = (i-radius) if (i-radius)>0 else 0
limitDown = (i+radius) if (i+radius)<(height-1) else (height-1)
for j in range(width):
summ = N = 0
limitLeft = (j-radius) if (j-radius)>0 else 0
limitRight = (j+radius) if (j+radius)<(width-1) else (width-1)
for x in range(limitUp,limitDown+1):
for y in range(limitLeft, limitRight+1):
summ += data[x, y]
N += 1
if (N>0):
summ /= N
mean_logy[i, j] = summ
else:
print("Value of width, height and radius is invalid")
return mean_logy
@nb.jit
def clip(data,height, width, limit):
result=np.zeros((height,width))
for i in range(height):
for j in range(width):
if (fabs(data[i, j])> limit):
if (data[i, j]>0):
result[i, j]=limit
else:
result[i, j]=-limit
else:
result[i, j]=data[i, j]
return result