Repository navigation
Expand file tree
/
Copy pathgeneration.py
More file actions
123 lines (107 loc) · 4.56 KB
/
Copy pathgeneration.py
File metadata and controls
123 lines (107 loc) · 4.56 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import cv2
import numpy as np
import os
from pyramid_generation import *
from pyramids_fusion import *
from contrast_weight import *
from saturation_weight import *
from exposedness_weight import *
from fusion import *
from fusion_correct import *
from ghosting_filter import *
# Images path
PATH = "Images/Venice-Grand-Canal"
images_path = []
for root, dirs, files in os.walk(PATH):
for file in files:
if file.endswith((".jpg", ".png", ".jpeg")):
images_path.append(os.path.join(root, file))
images = [cv2.imread(path) for path in images_path]
# Weights
cv2.imwrite("Generated/contrast_weight.jpg", laplacian_filter(images[0]))
cv2.imwrite("Generated/saturation_weight.jpg", saturation(images[0]))
cv2.imwrite("Generated/exposedness_weight.jpg", exp_weight(images[0]) * 255)
cv2.imwrite("Generated/image_weighted.jpg", images[0])
# Method 1
cv2.imwrite("Generated/fusion_method_1.jpg", fusion(images))
# Pyramids
gaussian_pyr, size = generate_gaussian_pyramid(images[0], 10)
for i in range(len(gaussian_pyr)):
cv2.imwrite("Generated/gaussian_" + str(i) + ".jpg", gaussian_pyr[i])
laplacian_pyr = generate_laplacian(gaussian_pyr, 10)
for i in range(len(gaussian_pyr)):
cv2.imwrite("Generated/laplacian_" + str(i) + ".jpg", laplacian_pyr[i])
# Method 2 + anti-ghosting
# Method 2 (with ghosting)
fusion_correct_image = fusion_correct(images)
fused_image_2 = np.clip(fusion_correct_image, 0, 255)
fused_image_2 = fused_image_2.astype(np.uint8)
cv2.imwrite("Generated/fusion_method_2.jpg", fused_image_2)
# Method 2 with anti-ghosting
ghosting_mask, ghosting_mask_opening = equalization_detection(images)
ghosting_mask_opening_dilated = morpho.dilation(ghosting_mask_opening, morpho.disk(1))
ghosting_mask_opening = ghosting_mask_opening[:, :, np.newaxis]
ghosting_mask_opening = ghosting_mask_opening.astype(fusion_correct_image.dtype)
ghosting_mask_opening_dilated = ghosting_mask_opening_dilated[:, :, np.newaxis]
ghosting_mask_opening_dilated = ghosting_mask_opening_dilated.astype(
fusion_correct_image.dtype
)
cv2.imwrite("Generated/mask.jpg", ghosting_mask * 255)
cv2.imwrite("Generated/mask_opening.jpg", ghosting_mask_opening * 255)
fused_image_replacement = (
fusion_correct_image * (1 - ghosting_mask_opening)
+ images[1] * ghosting_mask_opening
)
cv2.imwrite(
"Generated/fused_image_corrected_with_anti_ghost_replacement.jpg",
fused_image_replacement,
)
fused_image_ag = fusion_correct_image * (1 - ghosting_mask_opening)
fused_image_ag = cv2.inpaint(fused_image_ag, ghosting_mask_opening, 3, cv2.INPAINT_NS)
fused_image_ag_dilated = cv2.inpaint(
fused_image_ag,
ghosting_mask_opening_dilated,
7,
cv2.INPAINT_NS,
)
# Problem of type
fused_image_ag = fused_image_ag.astype(np.uint8)
fused_image_corrected = np.clip(fused_image_ag, 0, 255)
fused_image_ag_dilated = fused_image_ag_dilated.astype(np.uint8)
fused_image_corrected_dilated = np.clip(fused_image_ag_dilated, 0, 255)
cv2.imwrite(
"Generated/fused_image_corrected_with_anti_ghost_inpainted.jpg",
fused_image_corrected,
)
cv2.imwrite(
"Generated/fused_image_corrected_with_anti_ghost_inpainted.jpg",
fused_image_corrected_dilated,
)
# Method 2 with custom photo
PATH2 = "Images/Taken-Lucas"
images_path_2 = []
for root, dirs, files in os.walk(PATH2):
for file in files:
if file.endswith((".jpg", ".png", ".jpeg")):
images_path_2.append(os.path.join(root, file))
images_2 = [cv2.imread(path) for path in images_path_2]
fused_image_custom = fusion_correct(images_2)
fused_image_custom = np.clip(fused_image_custom, 0, 255)
fused_image_custom = fused_image_custom.astype(np.uint8)
cv2.imwrite("Generated/fusion_custom_photos.jpg", fused_image_custom)
# Changing wc,we,ws
# Importance on contrast
fused_image_contrast = fusion_correct(images, wc=1, we=100, ws=100)
fused_image_contrast = np.clip(fused_image_contrast, 0, 255)
fused_image_contrast = fused_image_contrast.astype(np.uint8)
cv2.imwrite("Generated/fusion_contrast_priority.jpg", fused_image_contrast)
# Importance on exposedness
fused_image_exposedness = fusion_correct(images, wc=100, we=1, ws=100)
fused_image_exposedness = np.clip(fused_image_exposedness, 0, 255)
fused_image_exposedness = fused_image_exposedness.astype(np.uint8)
cv2.imwrite("Generated/fusion_exposedness_priority.jpg", fused_image_exposedness)
# Importance on saturation
fused_image_saturation = fusion_correct(images, wc=100, we=100, ws=1)
fused_image_saturation = np.clip(fused_image_saturation, 0, 255)
fused_image_saturation = fused_image_saturation.astype(np.uint8)
cv2.imwrite("Generated/fusion_saturation_priority.jpg", fused_image_saturation)