Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from sklearn.cluster import KMeans
- import matplotlib.pyplot as plt
- import requests
- import cv2
- from math import sqrt
- def urlToImage(url):
- global image
- response = requests.get(url)
- image = np.asarray(bytearray(response.content), dtype='uint8')
- image = cv2.imdecode(image, cv2.IMREAD_COLOR)
- return image
- def imageProcessing(image):
- global img
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- height, width = image.shape[:2]
- img = cv2.resize(image, (int(round(width/10)), int(round(height/10))), interpolation = cv2.INTER_AREA)
- img = img.reshape((img.shape[0]*img.shape[1], 3))
- return img
- def findBrightness(img):
- global lighter, darker
- lighter = 0
- darker = 0
- for c in img:
- r = c[0]
- g = c[1]
- g = c[2]
- brightness = sqrt(0.299*r*r + 0.587*g*g + 0.114*b*b)
- if brightness > 0.5:
- lighter = lighter+1
- if brightness < 0.5:
- darker = darker+1
- if lighter>darker:
- return print('image is higher in brightness')
- if lighter<darker:
- return print('image is lower in brightness')
- urlToImage('https://www.gardapost.it/wp-content/uploads/2019/04/foresta-bosco.jpg')
- imageProcessing(image)
- findBrightness(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement