Skip to content

Commit f769dbc

Browse files
authored
Merge pull request #2 from M7mdSh3banX/feature/implement-brightness-adjustment-algorithm
app implementation for brightness-adjustment-algorithm
2 parents a9c74e4 + 518f848 commit f769dbc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
import cv2
3+
4+
5+
###############################################################################################
6+
# Create a function for brightness adjustment
7+
# First parameter: Input image that will be adjustment
8+
# Second parameter: Offset that specify you want brightness or darkness image
9+
def brightness_adjustment(image, offset):
10+
[row, column, channel] = image.shape
11+
new_image = np.zeros([row, column, channel], dtype=np.uint8)
12+
13+
for k in range(channel):
14+
for i in range(row):
15+
for j in range(column):
16+
new_value = image[i, j, k] + offset
17+
if new_value > 255:
18+
new_value = 255
19+
if new_value < 0:
20+
new_value = 0
21+
new_image[i, j, k] = new_value
22+
return new_image
23+
24+
25+
###############################################################################################
26+
27+
img = cv2.imread("/home/m7md43ban/Image Processing with Python/Codes/images/Squidward.jpeg")
28+
gray_img = brightness_adjustment(img, 50)
29+
30+
cv2.imshow('Original Image', img)
31+
print(img.shape)
32+
33+
cv2.imshow('Adjustment Image', gray_img)
34+
print(gray_img.shape)
35+
36+
cv2.waitKey(0)
37+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)