-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
42 lines (32 loc) · 1.27 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
#! python3
import cv2
import sys
import numpy as np
import color_harmonization
import util
import importlib
importlib.reload(color_harmonization)
importlib.reload(util)
image_filename = sys.argv[1]
color_image = cv2.imread(image_filename, cv2.IMREAD_COLOR)
height = color_image.shape[0]
width = color_image.shape[1]
HSV_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2HSV)
best_harmomic_scheme = color_harmonization.B(HSV_image)
print("Harmonic Scheme Type : ", best_harmomic_scheme.m)
print("Harmonic Scheme Alpha : ", best_harmomic_scheme.alpha)
histo = util.count_hue_histogram(HSV_image)
canvas = util.draw_polar_histogram(histo)
overlay = util.draw_harmonic_scheme(best_harmomic_scheme, canvas)
cv2.addWeighted(overlay, 0.5, canvas, 1 - 0.5, 0, canvas)
cv2.imwrite("hue_source.jpg", canvas)
num_superpixels = 200
new_HSV_image = best_harmomic_scheme.hue_shifted(HSV_image, num_superpixels)
histo = util.count_hue_histogram(new_HSV_image)
canvas = util.draw_polar_histogram(histo)
overlay = util.draw_harmonic_scheme(best_harmomic_scheme, canvas)
cv2.addWeighted(overlay, 0.5, canvas, 1 - 0.5, 0, canvas)
cv2.imwrite("hue_target.jpg", canvas)
result_image = cv2.cvtColor(new_HSV_image, cv2.COLOR_HSV2BGR)
result_image = result_image.astype('int')
cv2.imwrite("result.jpg", result_image)