forked from yossigandelsman/DoubleDIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg_fg_prep.py
31 lines (26 loc) · 960 Bytes
/
bg_fg_prep.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
import matplotlib.image as img
import glob
import numpy as np
from scipy.ndimage import filters, measurements, interpolation
from math import pi
import cv2
def image_histogram_equalization(image):
return cv2.equalizeHist(image)
for saliency in glob.glob("output_scaled/*.png"):
print(saliency)
# s = img.imread(saliency)
s = cv2.imread(saliency,0)
# print(s.shape)
image = image_histogram_equalization(s)
print(image.max())
image[image>255 - 15.5] = 255
image[image<=255 - 15.5] = 0
print(r"output_fg/" + saliency[len("output_scaled/"):])
cv2.imwrite(r"output_fg/" + saliency[len("output_scaled/"):], image)
image = image_histogram_equalization(s)
print(image.max())
v = np.zeros_like(image)
v[image>15.5] = 0
v[image<=15.5] = 255
print(r"output_bg/" + saliency[len("output_scaled/"):])
cv2.imwrite(r"output_bg/" + saliency[len("output_scaled/"):], v)