freealise commited on
Commit
370bccb
·
verified ·
1 Parent(s): 109579f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -465,45 +465,45 @@ def draw_mask(o, b, v, d, evt: gr.EventData):
465
 
466
 
467
  def read_file(sn,tn):
468
- s = cv2.imread(sn)
469
- s = cv2.cvtColor(s,cv2.COLOR_BGRA2LAB)
470
- t = cv2.imread(tn)
471
- t = cv2.cvtColor(t,cv2.COLOR_BGRA2LAB)
472
- return s, t
473
 
474
  def get_mean_and_std(x):
475
- x_mean, x_std = cv2.meanStdDev(x)
476
- x_mean = np.hstack(np.around(x_mean,2))
477
- x_std = np.hstack(np.around(x_std,2))
478
- return x_mean, x_std
479
 
480
  def color_transfer(base):
481
  global frames
482
  targets = []
483
 
484
  for n in range(len(frames)):
485
- targets.append(frames[base])
486
- if n != base:
487
- print("Converting picture "+str(n)+"...")
488
- s, t = read_file(frames[n],targets[n])
489
- s_mean, s_std = get_mean_and_std(s)
490
- t_mean, t_std = get_mean_and_std(t)
491
-
492
- height, width, channel = s.shape
493
- for i in range(0,height):
494
- for j in range(0,width):
495
- for k in range(0,channel):
496
- x = s[i,j,k]
497
- x = ((x-s_mean[k])*(t_std[k]/s_std[k]))+t_mean[k]
498
- # round or +0.5
499
- x = round(x)
500
- # boundary check
501
- x = 0 if x<0 else x
502
- x = 255 if x>255 else x
503
- s[i,j,k] = x
504
-
505
- s = cv2.cvtColor(s,cv2.COLOR_LAB2BGRA)
506
- cv2.imwrite(frames[n],s)
507
 
508
 
509
  js = """
 
465
 
466
 
467
  def read_file(sn,tn):
468
+ s = cv2.imread(sn)
469
+ s = cv2.cvtColor(s,cv2.COLOR_BGRA2LAB)
470
+ t = cv2.imread(tn)
471
+ t = cv2.cvtColor(t,cv2.COLOR_BGRA2LAB)
472
+ return s, t
473
 
474
  def get_mean_and_std(x):
475
+ x_mean, x_std = cv2.meanStdDev(x)
476
+ x_mean = np.hstack(np.around(x_mean,2))
477
+ x_std = np.hstack(np.around(x_std,2))
478
+ return x_mean, x_std
479
 
480
  def color_transfer(base):
481
  global frames
482
  targets = []
483
 
484
  for n in range(len(frames)):
485
+ targets.append(frames[base])
486
+ if n != base:
487
+ print("Converting picture "+str(n)+"...")
488
+ s, t = read_file(frames[n],targets[n])
489
+ s_mean, s_std = get_mean_and_std(s)
490
+ t_mean, t_std = get_mean_and_std(t)
491
+
492
+ height, width, channel = s.shape
493
+ for i in range(0,height):
494
+ for j in range(0,width):
495
+ for k in range(0,channel):
496
+ x = s[i,j,k]
497
+ x = ((x-s_mean[k])*(t_std[k]/s_std[k]))+t_mean[k]
498
+ # round or +0.5
499
+ x = round(x)
500
+ # boundary check
501
+ x = 0 if x<0 else x
502
+ x = 255 if x>255 else x
503
+ s[i,j,k] = x
504
+
505
+ s = cv2.cvtColor(s,cv2.COLOR_LAB2BGRA)
506
+ cv2.imwrite(frames[n],s)
507
 
508
 
509
  js = """