add saliency options, add image downsampling
Browse files- __pycache__/image.cpython-39.pyc +0 -0
- __pycache__/multi_image_process.cpython-39.pyc +0 -0
- app.py +26 -17
- image.py +22 -21
- multi_image_process.py +13 -3
- results/testing/palette_AMBIENT_PhotoChristian Bertrand 096..png +3 -0
- results/testing/palette_AMBIENT_PhotoChristian Bertrand 104..png +3 -0
- results/testing/palette_AMBIENT_PhotoChristian Bertrand 185..png +3 -0
- results/testing/recolor_AMBIENT_PhotoChristian Bertrand 096.jpeg +3 -0
- results/testing/recolor_AMBIENT_PhotoChristian Bertrand 104.jpeg +3 -0
- results/testing/recolor_AMBIENT_PhotoChristian Bertrand 185.jpeg +3 -0
- saliency/LDF/__pycache__/infer.cpython-39.pyc +0 -0
__pycache__/image.cpython-39.pyc
CHANGED
|
Binary files a/__pycache__/image.cpython-39.pyc and b/__pycache__/image.cpython-39.pyc differ
|
|
|
__pycache__/multi_image_process.cpython-39.pyc
CHANGED
|
Binary files a/__pycache__/multi_image_process.cpython-39.pyc and b/__pycache__/multi_image_process.cpython-39.pyc differ
|
|
|
app.py
CHANGED
|
@@ -50,7 +50,7 @@ if __name__ == "__main__":
|
|
| 50 |
file_types=["image"],
|
| 51 |
file_count="multiple"
|
| 52 |
)
|
| 53 |
-
uploaded_files = gr.Gallery(label="Input images", visible=False, columns=7, rows=1, height=
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Column(visible=False) as clear_button:
|
|
@@ -61,27 +61,36 @@ if __name__ == "__main__":
|
|
| 61 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, image_input])
|
| 62 |
|
| 63 |
gr.Markdown("### Select the parameters for recoloring")
|
| 64 |
-
with gr.
|
| 65 |
with gr.Group():
|
| 66 |
gr.Markdown("### Recoloring without other techiques")
|
| 67 |
-
num_center_grp = gr.Dropdown(choices=[1, 2, 3, 4, 5], value=3, label="Number of group palettes")
|
| 68 |
-
|
| 69 |
-
gr.
|
| 70 |
-
|
|
|
|
| 71 |
with gr.Group():
|
| 72 |
-
|
| 73 |
checkbox_input_wb = gr.Checkbox(value=False, label="Apply white balance correction")
|
| 74 |
with gr.Group():
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
with gr.Group():
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
with gr.Column():
|
| 87 |
gr.Markdown("### Outputs")
|
|
@@ -110,7 +119,7 @@ if __name__ == "__main__":
|
|
| 110 |
recolor_group_images,
|
| 111 |
inputs=[image_input, num_center_grp, num_center_sal, num_center_nonsal,
|
| 112 |
checkbox_input_wb,
|
| 113 |
-
checkbox_input_sal, checkbox_input_recolor_sal, checkbox_input_recolor_nonsal,
|
| 114 |
checkbox_input_cn, naming_thres],
|
| 115 |
outputs=[output_gallery_recolor, output_gallery_palette_in, output_gallery_palette_out, output_gallery_palette_group]
|
| 116 |
)
|
|
|
|
| 50 |
file_types=["image"],
|
| 51 |
file_count="multiple"
|
| 52 |
)
|
| 53 |
+
uploaded_files = gr.Gallery(label="Input images", visible=False, columns=7, rows=1, height=250)
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Column(visible=False) as clear_button:
|
|
|
|
| 61 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, image_input])
|
| 62 |
|
| 63 |
gr.Markdown("### Select the parameters for recoloring")
|
| 64 |
+
with gr.Group():
|
| 65 |
with gr.Group():
|
| 66 |
gr.Markdown("### Recoloring without other techiques")
|
| 67 |
+
num_center_grp = gr.Dropdown(choices=[1, 2, 3, 4, 5, 6, 7], value=3, label="Number of group palettes")
|
| 68 |
+
# num_center_grp = gr.Slider(label="Number of group palettes", minimum=1, maximum=7, value=3, step=1)
|
| 69 |
+
with gr.Group():
|
| 70 |
+
gr.Markdown("### Recoloring with other techiques")
|
| 71 |
+
gr.Markdown("")
|
| 72 |
with gr.Group():
|
| 73 |
+
gr.Markdown("<center>white balance<center>")
|
| 74 |
checkbox_input_wb = gr.Checkbox(value=False, label="Apply white balance correction")
|
| 75 |
with gr.Group():
|
| 76 |
+
gr.Markdown("<center>saliency detection<center>")
|
| 77 |
+
with gr.Row():
|
| 78 |
+
checkbox_input_sal = gr.Checkbox(value=False, label="Apply saliency")
|
| 79 |
+
sal_method = gr.Dropdown(choices=['LDF (accurate)','ft (fast)','rbd (fast)'], value='LDF', label="saliency detection method")
|
| 80 |
+
with gr.Row():
|
| 81 |
+
num_center_sal = gr.Dropdown(choices=[1, 2, 3, 4], value=1, label="Number of salient palettes")
|
| 82 |
+
num_center_nonsal = gr.Dropdown(choices=[1, 2, 3, 4], value=1, label="Number of non-salient palettes")
|
| 83 |
+
# num_center_sal = gr.Slider(label="Number of salient palettes", minimum=1, maximum=4, value=1, step=1)
|
| 84 |
+
# num_center_nonsal = gr.Slider(label="Number of non-salient palettes", minimum=1, maximum=4, value=1, step=1)
|
| 85 |
+
with gr.Row():
|
| 86 |
+
checkbox_input_recolor_sal = gr.Checkbox(value=False, label="Recolor salient colors only")
|
| 87 |
+
checkbox_input_recolor_nonsal = gr.Checkbox(value=False, label="Recolor non-salient colors only")
|
| 88 |
+
|
| 89 |
with gr.Group():
|
| 90 |
+
gr.Markdown("<center>color naming<center>")
|
| 91 |
+
with gr.Row():
|
| 92 |
+
checkbox_input_cn = gr.Checkbox(value=False, label="Apply color naming")
|
| 93 |
+
naming_thres = gr.Textbox(value=0.8, label="Threshold of color naming", placeholder=0.8)
|
| 94 |
|
| 95 |
with gr.Column():
|
| 96 |
gr.Markdown("### Outputs")
|
|
|
|
| 119 |
recolor_group_images,
|
| 120 |
inputs=[image_input, num_center_grp, num_center_sal, num_center_nonsal,
|
| 121 |
checkbox_input_wb,
|
| 122 |
+
checkbox_input_sal, sal_method, checkbox_input_recolor_sal, checkbox_input_recolor_nonsal,
|
| 123 |
checkbox_input_cn, naming_thres],
|
| 124 |
outputs=[output_gallery_recolor, output_gallery_palette_in, output_gallery_palette_out, output_gallery_palette_group]
|
| 125 |
)
|
image.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# import cv2
|
| 2 |
import os
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
from PIL import Image
|
|
@@ -16,6 +17,18 @@ class BaseImage:
|
|
| 16 |
self.filename = os.path.basename(filepath.name)
|
| 17 |
self.image = Image.open(filepath)
|
| 18 |
self.img_rgb = np.asarray(self.image).astype(dtype=np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
self.img_lab = rgb2lab(self.img_rgb)
|
| 20 |
|
| 21 |
self.bin_size = 16
|
|
@@ -28,36 +41,23 @@ class BaseImage:
|
|
| 28 |
# self.if_correct_wb = if_correct_wb
|
| 29 |
# self.if_saliency = if_saliency
|
| 30 |
# self.saliency_threshold = sal_thres
|
| 31 |
-
self.cdiff_threshold = 30
|
| 32 |
-
self.sal_threshold = 0.9
|
| 33 |
self.applied_wb = False
|
| 34 |
# self.valid_class = [0,1]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
# self.hist_value, self.hist_count, \
|
| 38 |
-
# self.c_center, self.c_density, \
|
| 39 |
-
# self.c_img_label = self.extract_palette(if_wb=self.if_correct_wb,
|
| 40 |
-
# if_saliency=self.if_saliency,
|
| 41 |
-
# sal_thres=self.saliency_threshold)
|
| 42 |
-
|
| 43 |
-
# self.inital_info(self.if_correct_wb,
|
| 44 |
-
# self.if_saliency,
|
| 45 |
-
# self.saliency_threshold)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# self.hist_value, self.hist_count, self.c_center, self.c_density, self.c_img_label = self.extract_palette(if_wb=self.if_correct_wb, if_saliency=False)
|
| 49 |
-
# self.hist_value_sal, self.hist_count_sal, self.c_center_sal, self.c_density_sal, self.c_img_label_sal = self.extract_palette(if_wb=self.if_correct_wb, if_saliency=True, sal_thres=self.saliency_threshold)
|
| 50 |
|
| 51 |
-
def inital_info(self, if_correct_wb, if_saliency, wb_thres, sal_thres, valid_class):
|
| 52 |
self.hist_value, self.hist_count, \
|
| 53 |
self.c_center, self.c_density, \
|
| 54 |
self.c_img_label, self.sal_links = self.extract_salient_palette(if_wb=if_correct_wb,
|
| 55 |
if_saliency=if_saliency,
|
| 56 |
wb_thres=wb_thres,
|
|
|
|
| 57 |
sal_thres=sal_thres,
|
| 58 |
valid_class=valid_class)
|
| 59 |
|
| 60 |
-
self.label_colored = self.cal_color_segment()
|
| 61 |
|
| 62 |
def get_rgb_image(self):
|
| 63 |
return self.img_rgb
|
|
@@ -131,6 +131,7 @@ class BaseImage:
|
|
| 131 |
sal_map = get_saliency_ft(img_rgb)
|
| 132 |
elif method == 'rbd':
|
| 133 |
sal_map = get_saliency_mbd(img_rgb)
|
|
|
|
| 134 |
return sal_map
|
| 135 |
|
| 136 |
|
|
@@ -159,7 +160,7 @@ class BaseImage:
|
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
-
def extract_salient_palette(self, if_wb=False, if_saliency=False, wb_thres=5, sal_thres=0.9, valid_class=[0,1]):
|
| 163 |
|
| 164 |
img_rgb = self.img_rgb.copy()
|
| 165 |
if if_wb:
|
|
@@ -182,8 +183,8 @@ class BaseImage:
|
|
| 182 |
return hist_value, hist_count, center, density, colorlabel, sal_links
|
| 183 |
|
| 184 |
else:
|
| 185 |
-
self.sal_map = self.saliency_detection(
|
| 186 |
-
label_sem = np.zeros_like(
|
| 187 |
# print(label_sem.shape, self.sal_map.shape)
|
| 188 |
label_sem[self.sal_map > sal_thres]=1
|
| 189 |
|
|
|
|
| 1 |
# import cv2
|
| 2 |
import os
|
| 3 |
+
import cv2
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
from PIL import Image
|
|
|
|
| 17 |
self.filename = os.path.basename(filepath.name)
|
| 18 |
self.image = Image.open(filepath)
|
| 19 |
self.img_rgb = np.asarray(self.image).astype(dtype=np.uint8)
|
| 20 |
+
|
| 21 |
+
anchor = 256
|
| 22 |
+
width = self.img_rgb.shape[1]
|
| 23 |
+
height = self.img_rgb.shape[0]
|
| 24 |
+
if width > 512 or height > 512:
|
| 25 |
+
self.if_downsample = True
|
| 26 |
+
if width >= height:
|
| 27 |
+
dim = (np.floor(width/height*anchor).astype(int), anchor)
|
| 28 |
+
else:
|
| 29 |
+
dim = (anchor, np.floor(height/width*anchor).astype(int))
|
| 30 |
+
self.img_rgb = cv2.resize(self.img_rgb, dim, interpolation=cv2.INTER_LINEAR)
|
| 31 |
+
|
| 32 |
self.img_lab = rgb2lab(self.img_rgb)
|
| 33 |
|
| 34 |
self.bin_size = 16
|
|
|
|
| 41 |
# self.if_correct_wb = if_correct_wb
|
| 42 |
# self.if_saliency = if_saliency
|
| 43 |
# self.saliency_threshold = sal_thres
|
| 44 |
+
# self.cdiff_threshold = 30
|
| 45 |
+
# self.sal_threshold = 0.9
|
| 46 |
self.applied_wb = False
|
| 47 |
# self.valid_class = [0,1]
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
def inital_info(self, if_correct_wb, if_saliency, wb_thres, sal_method, sal_thres, valid_class):
|
| 51 |
self.hist_value, self.hist_count, \
|
| 52 |
self.c_center, self.c_density, \
|
| 53 |
self.c_img_label, self.sal_links = self.extract_salient_palette(if_wb=if_correct_wb,
|
| 54 |
if_saliency=if_saliency,
|
| 55 |
wb_thres=wb_thres,
|
| 56 |
+
sal_method=sal_method,
|
| 57 |
sal_thres=sal_thres,
|
| 58 |
valid_class=valid_class)
|
| 59 |
|
| 60 |
+
# self.label_colored = self.cal_color_segment()
|
| 61 |
|
| 62 |
def get_rgb_image(self):
|
| 63 |
return self.img_rgb
|
|
|
|
| 131 |
sal_map = get_saliency_ft(img_rgb)
|
| 132 |
elif method == 'rbd':
|
| 133 |
sal_map = get_saliency_mbd(img_rgb)
|
| 134 |
+
|
| 135 |
return sal_map
|
| 136 |
|
| 137 |
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
+
def extract_salient_palette(self, if_wb=False, if_saliency=False, wb_thres=5, sal_method='LDF', sal_thres=0.9, valid_class=[0,1]):
|
| 164 |
|
| 165 |
img_rgb = self.img_rgb.copy()
|
| 166 |
if if_wb:
|
|
|
|
| 183 |
return hist_value, hist_count, center, density, colorlabel, sal_links
|
| 184 |
|
| 185 |
else:
|
| 186 |
+
self.sal_map = self.saliency_detection(img_rgb, method=sal_method)
|
| 187 |
+
label_sem = np.zeros_like(img_rgb[:,:,0])
|
| 188 |
# print(label_sem.shape, self.sal_map.shape)
|
| 189 |
label_sem[self.sal_map > sal_thres]=1
|
| 190 |
|
multi_image_process.py
CHANGED
|
@@ -92,6 +92,7 @@ def solve_grp_palette(images, mode, bin_size,
|
|
| 92 |
image.inital_info(if_wb,
|
| 93 |
False,
|
| 94 |
wb_thres,
|
|
|
|
| 95 |
0.9,
|
| 96 |
[0, 1])
|
| 97 |
|
|
@@ -144,7 +145,7 @@ def solve_grp_palette_wsal(images, mode, bin_size,
|
|
| 144 |
lightness=70., eta=1e10, gamma=0, iteration=10,
|
| 145 |
if_wb=False, wb_thres=30,
|
| 146 |
if_saliency=True, sal_thres=0.9, valid_class=[0,1],
|
| 147 |
-
sal_center=1, nonsal_center=1,
|
| 148 |
recolor_nonsal_only=False, recolor_sal_only=False,
|
| 149 |
if_cn=False, naming_thres=0.5):
|
| 150 |
|
|
@@ -175,6 +176,7 @@ def solve_grp_palette_wsal(images, mode, bin_size,
|
|
| 175 |
image.inital_info(if_wb,
|
| 176 |
if_saliency,
|
| 177 |
wb_thres,
|
|
|
|
| 178 |
sal_thres,
|
| 179 |
valid_class)
|
| 180 |
|
|
@@ -288,7 +290,7 @@ def solve_grp_palette_wsal(images, mode, bin_size,
|
|
| 288 |
def recolor_group_images(inp_images,
|
| 289 |
num_center_grp, num_center_sal, num_center_nonsal,
|
| 290 |
if_wb,
|
| 291 |
-
if_sal, recolor_nonsal_only, recolor_sal_only,
|
| 292 |
if_cn, naming_thres,
|
| 293 |
save_dir='./results/testing'):
|
| 294 |
|
|
@@ -309,10 +311,18 @@ def recolor_group_images(inp_images,
|
|
| 309 |
images[img_id] = BaseImage(image)
|
| 310 |
|
| 311 |
if if_sal:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
palette_src, palette_grp, palette_tgt, links, src_sal_size, grp_sal_size = solve_grp_palette_wsal(images, mode, bin_size,
|
| 313 |
lightness=70., eta=1e10, gamma=0, iteration=10,
|
| 314 |
if_wb=if_wb, wb_thres=30,
|
| 315 |
-
if_saliency=True, sal_thres=0.5, valid_class=[0,1],
|
| 316 |
sal_center=num_center_sal, nonsal_center=num_center_nonsal,
|
| 317 |
recolor_nonsal_only=recolor_nonsal_only, recolor_sal_only=recolor_sal_only,
|
| 318 |
if_cn=if_cn, naming_thres=float(naming_thres))
|
|
|
|
| 92 |
image.inital_info(if_wb,
|
| 93 |
False,
|
| 94 |
wb_thres,
|
| 95 |
+
'LDF',
|
| 96 |
0.9,
|
| 97 |
[0, 1])
|
| 98 |
|
|
|
|
| 145 |
lightness=70., eta=1e10, gamma=0, iteration=10,
|
| 146 |
if_wb=False, wb_thres=30,
|
| 147 |
if_saliency=True, sal_thres=0.9, valid_class=[0,1],
|
| 148 |
+
sal_center=1, nonsal_center=1, sal_method='LDF',
|
| 149 |
recolor_nonsal_only=False, recolor_sal_only=False,
|
| 150 |
if_cn=False, naming_thres=0.5):
|
| 151 |
|
|
|
|
| 176 |
image.inital_info(if_wb,
|
| 177 |
if_saliency,
|
| 178 |
wb_thres,
|
| 179 |
+
sal_method,
|
| 180 |
sal_thres,
|
| 181 |
valid_class)
|
| 182 |
|
|
|
|
| 290 |
def recolor_group_images(inp_images,
|
| 291 |
num_center_grp, num_center_sal, num_center_nonsal,
|
| 292 |
if_wb,
|
| 293 |
+
if_sal, sal_method, recolor_nonsal_only, recolor_sal_only,
|
| 294 |
if_cn, naming_thres,
|
| 295 |
save_dir='./results/testing'):
|
| 296 |
|
|
|
|
| 311 |
images[img_id] = BaseImage(image)
|
| 312 |
|
| 313 |
if if_sal:
|
| 314 |
+
if sal_method == 'LDF (accurate)':
|
| 315 |
+
sal_method = 'LDF'
|
| 316 |
+
elif sal_method == 'ft (fast)':
|
| 317 |
+
sal_method = 'ft'
|
| 318 |
+
elif sal_method == 'rbd (fast)':
|
| 319 |
+
sal_method = 'rbd'
|
| 320 |
+
else:
|
| 321 |
+
raise ValueError('saliency method not supported!')
|
| 322 |
palette_src, palette_grp, palette_tgt, links, src_sal_size, grp_sal_size = solve_grp_palette_wsal(images, mode, bin_size,
|
| 323 |
lightness=70., eta=1e10, gamma=0, iteration=10,
|
| 324 |
if_wb=if_wb, wb_thres=30,
|
| 325 |
+
if_saliency=True, sal_thres=0.5, valid_class=[0,1], sal_method=sal_method,
|
| 326 |
sal_center=num_center_sal, nonsal_center=num_center_nonsal,
|
| 327 |
recolor_nonsal_only=recolor_nonsal_only, recolor_sal_only=recolor_sal_only,
|
| 328 |
if_cn=if_cn, naming_thres=float(naming_thres))
|
results/testing/palette_AMBIENT_PhotoChristian Bertrand 096..png
ADDED
|
Git LFS Details
|
results/testing/palette_AMBIENT_PhotoChristian Bertrand 104..png
ADDED
|
Git LFS Details
|
results/testing/palette_AMBIENT_PhotoChristian Bertrand 185..png
ADDED
|
Git LFS Details
|
results/testing/recolor_AMBIENT_PhotoChristian Bertrand 096.jpeg
ADDED
|
Git LFS Details
|
results/testing/recolor_AMBIENT_PhotoChristian Bertrand 104.jpeg
ADDED
|
Git LFS Details
|
results/testing/recolor_AMBIENT_PhotoChristian Bertrand 185.jpeg
ADDED
|
Git LFS Details
|
saliency/LDF/__pycache__/infer.cpython-39.pyc
CHANGED
|
Binary files a/saliency/LDF/__pycache__/infer.cpython-39.pyc and b/saliency/LDF/__pycache__/infer.cpython-39.pyc differ
|
|
|