-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetauto.py
More file actions
27 lines (23 loc) · 811 Bytes
/
setauto.py
File metadata and controls
27 lines (23 loc) · 811 Bytes
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
#auto sets the brightness and contrast of an image using generate.java as a reference
import cv2
import numpy as np
def setauto(img):
#convert image to YUV
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
#split the image into Y, U, and V channels
y, u, v = cv2.split(yuv)
#find the mean and standard deviation of the Y channel
mean, std = cv2.meanStdDev(y)
#set the brightness and contrast
brightness = mean[0][0]
contrast = std[0][0]
#return the brightness and contrast
return brightness, contrast
if __name__ == "__main__":
#read the image
img = cv2.imread("image.jpg")
#set the brightness and contrast
brightness, contrast = setauto(img)
#print the brightness and contrast
print("Brightness: ", brightness)
print("Contrast: ", contrast)