生成一个值来反映图像的平均亮度
我需要确定图像是否高于特定亮度。 我想使用 0 - 255 的范围生成一个在此范围内的值来反映图像亮度。
即白色图像为 255,黑色图像为 0。
所有这些都需要通过我目前正在构建的 bash 脚本进行。 我不知道什么图像库可以为我做到这一点。
I need to determine if an image is above a certain brightness.
Using a scale of 0 - 255 I want to generate a value within this range to reflect the image brightness.
i.e. a white image is 255 and a black image is 0.
All this needs to take place via a bash script I am building up at the moment.
I have no idea what image lib could do this for me though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 ImageMagick 灰色统计 或 直方图
Try ImageMagick gray stats or histogram
一般来说,这是信号处理的经典问题之一,根据如何定义“亮度”,有多种方法。图像的“亮度”、声音信号的“响度”等通常是相同的。
可以用作通用“亮度”的一些想法是:
有多个图像库可以产生良好的结果。从 shell 脚本中使用的最简单的可能是 ImageMagick/GraphicsMagick - 如果您愿意,您可以获得简单的平均值并执行一些更复杂的直方图来检查百分位数。
Generally, it's one of the classic problems of signal processing and there are several approaches, based on how do you define "brightness". It's generally the same for "brightness" of an image, "loudness" of a sound signal, etc.
Some ideas of what you can use as a generic "brightness" is:
There are multiple image libraries that can yield good results. The easiest one to use from a shell script is probably ImageMagick/GraphicsMagick - you can get both simple averages and do some more complex histogramming to check out percentiles if you want to.