|
a |
|
b/Dataset/bayesnoiseremoval.py |
|
|
1 |
import numpy as np |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
class BayesPreprocessor: |
|
|
5 |
|
|
|
6 |
@staticmethod |
|
|
7 |
def bayes_noise_removal(image, o): |
|
|
8 |
|
|
|
9 |
# implement image processing |
|
|
10 |
S1 = image |
|
|
11 |
S2 = 255 - S1 |
|
|
12 |
S3 = S1 + S2 |
|
|
13 |
try: |
|
|
14 |
w = S2 / S3 |
|
|
15 |
except ZeroDivisionError: |
|
|
16 |
w = 0 |
|
|
17 |
w = np.divide(S2, S3) |
|
|
18 |
p = np.divide(S3, w) |
|
|
19 |
try: |
|
|
20 |
p = S3 / w |
|
|
21 |
except ZeroDivisionError: |
|
|
22 |
p = 0 |
|
|
23 |
|
|
|
24 |
dv = np.log(np.i0((p * np.sinc(w) * S1) / o ** 2)) + np.log(np.i0((p * np.sinc(1 - w) * S2) / o ** 2)) - p * ( |
|
|
25 |
((np.sinc(w)) ** 2 + (np.sinc(1 - w)) ** 2) / (2 * o ** 2)) |
|
|
26 |
|
|
|
27 |
dv[dv < 0] = 0 |
|
|
28 |
|
|
|
29 |
return dv |