查找图像是亮还是暗 [英] Find If Image Is Bright Or Dark

查看:85
本文介绍了查找图像是亮还是暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用OpenCV在Python 3中编写函数,该函数接受图像和阈值,并在严重模糊和降低质量(更快越好)后返回暗"或亮".听起来可能有些含糊,但是任何可行的方法都可以.

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.

推荐答案

您可以尝试以下方法:

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))

这篇关于查找图像是亮还是暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆