-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambdacode.py
75 lines (56 loc) · 1.96 KB
/
lambdacode.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 9 11:28:18 2020
@author: Radu
"""
import cv2
import numpy as np
# read image
src = cv2.imread('images/github_avatar.jpg', cv2.IMREAD_GRAYSCALE)
# Resize to TARGET x TARGET in landscape or portrait
TARGET = 512
TARGET_PORTRAIT = 350
org_height = src.shape[0]
org_width = src.shape[1]
scale_percent = 1
landscape = True
if (org_height>org_width):
scale_percent = TARGET_PORTRAIT / org_height
landscape = False
else:
scale_percent = TARGET / org_width
resulting_height = int(src.shape[0] * scale_percent)
if (resulting_height>TARGET_PORTRAIT):
scale_percent = TARGET_PORTRAIT / org_height
landscape = False
# new size
width = int(src.shape[1] * scale_percent)
height = int(src.shape[0] * scale_percent)
dsize = (width, height)
src = cv2.resize(src, dsize)
# apply guassian blur on src image
src = cv2.GaussianBlur(src,(3,3),cv2.BORDER_DEFAULT)
src = cv2.Sobel(src,cv2.CV_8U,1,1,ksize=5)
top_pixel = np.percentile(src,97)
src = cv2.convertScaleAbs(src, alpha=(250/top_pixel), beta=0)
src = cv2.GaussianBlur(src,(3,3),cv2.BORDER_DEFAULT)
# display input and output image
# cv2.imshow("Gaussian Smoothing",np.hstack((resized, blured)))
# cv2.waitKey(0) # waits until a key is pressed
# cv2.destroyAllWindows() # destroys the window showing image
#%%
bck = cv2.imread('images/blackboard_wide_2.png', cv2.IMREAD_GRAYSCALE)
beta = 0.5
offset_x = 250
offset_y = 5
for y in range(src.shape[0]):
for x in range(src.shape[1]):
bck[y+offset_y,x+offset_x] = np.uint8(bck[y+offset_y,x+offset_x]+beta*src[y,x])
if not landscape:
# clip image
actual_width = 250 + src.shape[1] + 5
actual_width = actual_width if actual_width <= 768 else 768
bck = bck[:,0:actual_width]
cv2.imshow("Blackboard Smoothing",bck)
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows()