Sanket commited on
Commit
14b30fc
1 Parent(s): bcdd461

improving darken image

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import torch
3
  import torch.nn as nn
4
  import torchvision.transforms as transforms
5
- from PIL import Image, ImageEnhance
6
 
7
  norm_layer = nn.InstanceNorm2d
8
 
@@ -117,9 +117,18 @@ def predict(input_img, ver):
117
  drawing = model1(input_img)[0].detach()
118
 
119
  drawing = transforms.ToPILImage()(drawing)
120
- enhancer = ImageEnhance.Brightness(drawing)
121
- factor = 0.6 # darkens the image
122
- im_output = enhancer.enhance(factor)
 
 
 
 
 
 
 
 
 
123
  return im_output
124
 
125
 
 
2
  import torch
3
  import torch.nn as nn
4
  import torchvision.transforms as transforms
5
+ from PIL import Image
6
 
7
  norm_layer = nn.InstanceNorm2d
8
 
 
117
  drawing = model1(input_img)[0].detach()
118
 
119
  drawing = transforms.ToPILImage()(drawing)
120
+
121
+ # Making image darker
122
+ source = drawing.split()
123
+
124
+ R, G, B = 0, 1, 2
125
+ constant = 2 # constant by which each pixel is divided
126
+
127
+ Red = source[R].point(lambda i: i < 150 & i / constant)
128
+ Green = source[G].point(lambda i: i < 150 & i / constant)
129
+ Blue = source[B].point(lambda i: i < 150 & i / constant)
130
+
131
+ im = Image.merge(im.mode, (Red, Green, Blue))
132
  return im_output
133
 
134