Matthew-Gallardo
/
Detection-of-GAN-Generated-Images-using-Spatial-Frequency-Domain-Fusion-Data
Public
forked from Deynnnyellll/Detection-of-GAN-Generated-Images-using-Spatial-Frequency-Domain-Fusion-Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_binary_pattern.py
More file actions
40 lines (33 loc) · 1.17 KB
/
local_binary_pattern.py
File metadata and controls
40 lines (33 loc) · 1.17 KB
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
import numpy as np
import timeit
from numba import jit
@jit(nopython=True)
def get_pixel(image, x, y):
if 0 <= x < len(image) and 0 <= y < len(image[0]):
return image[x][y]
return 0
@jit(nopython=True)
def lbp_calculated_pixel(image, x, y):
center = image[x][y]
val_ar = []
val_ar.append(get_pixel(image, x - 1, y - 1) >= center)
val_ar.append(get_pixel(image, x - 1, y) >= center)
val_ar.append(get_pixel(image, x - 1, y + 1) >= center)
val_ar.append(get_pixel(image, x, y + 1) >= center)
val_ar.append(get_pixel(image, x + 1, y + 1) >= center)
val_ar.append(get_pixel(image, x + 1, y) >= center)
val_ar.append(get_pixel(image, x + 1, y - 1) >= center)
val_ar.append(get_pixel(image, x, y - 1) >= center)
val = 0
for i in range(len(val_ar)):
val += val_ar[i] << i
return val
@jit(nopython=True)
def lbp(image):
height, width = len(image), len(image[0])
lbp_values = np.zeros((height, width), dtype=np.uint8)
for i in range(1, height - 1):
for j in range(1, width - 1):
lbp_value = lbp_calculated_pixel(image, i, j)
lbp_values[i][j] = lbp_value
return lbp_values