Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find If Image Is Bright Or Dark

I would like to know how to write a function in Python 3 using OpenCV which takes in an image and a threshold and returns either 'dark' or 'light' after heavily blurring it and reducing quality (faster the better). This might sound vague , but anything that just works will do.

like image 812
Farhan R. Avatar asked Sep 25 '18 20:09

Farhan R.


1 Answers

You could try this :

import imageio
import numpy as np

f = imageio.imread(filename, as_gray=True)

def img_estim(img, thrshld):
    is_light = np.mean(img) > thrshld
    return 'light' if is_light else 'dark'

print(img_estim(f, 127))
like image 159
SpghttCd Avatar answered Sep 26 '22 17:09

SpghttCd