如何判断图像是否较暗? (高对比度、低亮度)

发布于 2024-12-12 17:20:33 字数 148 浏览 2 评论 0原文

作为我正在从事的项目的一部分,我需要使用 CLI Linux 应用程序简单地分析图片并确定其图像是否较暗(高对比度、低亮度)。

到目前为止,我发现我可以使用 ImageMagick 来获取图像的详细信息,但不确定如何使用该数据......或者是否有更简单的解决方案?

As part of a project I am working on, I need to simply analyze a picture using a CLI Linux application and determining if its dark image (high contrast, low brightness).

So far, I figured out I can use ImageMagick to get verbose information of the image, but not sure how to use that data...or is there a simpler solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

暮凉 2024-12-19 17:20:34

您可以将图像缩放到非常小的图像 - 尺寸为 1x1 像素并代表原始图像的“平均颜色”:

 convert  original.jpeg  -resize 1x1  1pixel-original.jpeg

然后首先研究该单个像素的颜色,

convert  1pixel-original.jpeg  1pixel-jpeg.txt 

然后

cat 1pixel-jpeg.txt

  # ImageMagick pixel enumeration: 1,1,255,srgb
  0,0: (130,113,108)  #82716C  srgb(130,113,108)

您也可以在一个图像中获得相同的结果go:

convert  original.jpeg  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,srgb
  0,0: (130,113,108)  #82716C  srgb(130,113,108)

通过这种方式,您可以获取输入图像的原始颜色空间中的“平均像素”值,您可以评估其“亮度”(无论您如何定义)。

您可以将图像转换为灰度,然后调整大小。通过这种方式,您将获得灰度值作为“亮度”的度量:

convert  original.jpeg  -colorspace gray  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,gray
  0,0: (117,117,117)  #757575  gray(117,117,117)

您还可以将图像转换为 HSB 空间(色调、饱和度、亮度)并执行相同的操作:

convert  original.jpeg  -colorspace hsb  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,hsb
  0,0: ( 61, 62,134)  #3D3E86  hsb(24.1138%,24.1764%,52.4941%)

您在此处看到的“亮度”值(或者134#8652.4941%)可能是您想知道的。

You could scale the image to a very small one -- one that has a dimension of 1x1 pixels and represents the "average color" of your original image:

 convert  original.jpeg  -resize 1x1  1pixel-original.jpeg

Then investigate that single pixel's color, first

convert  1pixel-original.jpeg  1pixel-jpeg.txt 

then

cat 1pixel-jpeg.txt

  # ImageMagick pixel enumeration: 1,1,255,srgb
  0,0: (130,113,108)  #82716C  srgb(130,113,108)

You can also get the same result in one go:

convert  original.jpeg  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,srgb
  0,0: (130,113,108)  #82716C  srgb(130,113,108)

This way you get the values for your "avarage pixel" in the original color space of your input image, which you can evaluate for its 'brightness' (however you define that).

You could convert your image to grayscale and then resize. This way you'll get the gray value as a measure of 'brightness':

convert  original.jpeg  -colorspace gray  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,gray
  0,0: (117,117,117)  #757575  gray(117,117,117)

You can also convert your image to HSB space (hue, saturation, brightness) and do the same thing:

convert  original.jpeg  -colorspace hsb  -resize 1x1  txt:-

  # ImageMagick pixel enumeration: 1,1,255,hsb
  0,0: ( 61, 62,134)  #3D3E86  hsb(24.1138%,24.1764%,52.4941%)

The 'brightness' values you see here (either of 134, #86 or 52.4941%) is probably what you want to know.

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