生成一个值来反映图像的平均亮度

发布于 2024-10-03 19:51:09 字数 144 浏览 0 评论 0原文

我需要确定图像是否高于特定亮度。 我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧话新听 2024-10-10 19:51:09

尝试使用 ImageMagick 灰色统计直方图

convert rose: -colorspace gray -format "%[fx:100*mean]%%" info:

Try ImageMagick gray stats or histogram

convert rose: -colorspace gray -format "%[fx:100*mean]%%" info:
咿呀咿呀哟 2024-10-10 19:51:09

一般来说,这是信号处理的经典问题之一,根据如何定义“亮度”,有多种方法。图像的“亮度”、声音信号的“响度”等通常是相同的。

可以用作通用“亮度”的一些想法是:

  • 所有像素的平均值(即所有亮度的总和)所有像素,然后除以像素总数,即宽度*高度)。
  • 建立亮度分布的直方图,然后在该直方图中选择这样的点x,使得图像中所有像素的 98%(95%、90%、70% - 这个数字可能会有所不同)比这个x亮度低。这称为百分位数。
  • 计算所有像素的“均方根”(RMS)(将所有像素的平方相加) ,除以像素总数,从中提取平方根)。

有多个图像库可以产生良好的结果。从 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:

  • Average value of all the pixels (i.e. sum up all the brightnesses of all the pixels, then divide by total amount of pixels, i.e. width * height).
  • Build up a histogram of brightness distribution, then choose such point x in that histogram that 98% (95%, 90%, 70% - this number can vary) of all the pixels in your image would be less bright than this x. It's called percentile.
  • Calculate "root mean square" (RMS) for all the pixels (sum up squares of all the pixels, divide by total amount of pixels, extract square root from this one).

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文