BilalSardar commited on
Commit
c618c24
·
1 Parent(s): 16d68d4

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +45 -0
  2. cherry-blossom.jpg +0 -0
  3. road.jpg +0 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ import os
4
+
5
+ #input_dir = "input_images/"
6
+ # input_dir = ""
7
+ # input_image_list = os.listdir(input_dir)
8
+
9
+ #output_dir = "output_images/"
10
+ # output_dir = ""
11
+
12
+ def get_mean_and_std(x):
13
+ x_mean, x_std = cv2.meanStdDev(x)
14
+ x_mean = np.hstack(np.around(x_mean,2))
15
+ x_std = np.hstack(np.around(x_std,2))
16
+ return x_mean, x_std
17
+
18
+ template_img = cv2.imread('cherry-blossom.jpg')
19
+ template_img = cv2.cvtColor(template_img,cv2.COLOR_BGR2LAB)
20
+ template_mean, template_std = get_mean_and_std(template_img)
21
+
22
+ # for img in (input_image_list):
23
+ # print(img)
24
+ #input_img = cv2.imread(input_dir+img)
25
+ input_img = cv2.imread('road.jpg')
26
+ input_img = cv2.cvtColor(input_img,cv2.COLOR_BGR2LAB)
27
+
28
+
29
+ img_mean, img_std = get_mean_and_std(input_img)
30
+
31
+
32
+ height, width, channel = input_img.shape
33
+ for i in range(0,height):
34
+ for j in range(0,width):
35
+ for k in range(0,channel):
36
+ x = input_img[i,j,k]
37
+ x = ((x-img_mean[k])*(template_std[k]/img_std[k]))+template_mean[k]
38
+ x = round(x)
39
+ # boundary check
40
+ x = 0 if x<0 else x
41
+ x = 255 if x>255 else x
42
+ input_img[i,j,k] = x
43
+
44
+ input_img= cv2.cvtColor(input_img,cv2.COLOR_LAB2BGR)
45
+ cv2.imwrite("modified.jpg", input_img)
cherry-blossom.jpg ADDED
road.jpg ADDED