问题描述
作为我正在开发的一个项目的一部分,我需要使用CLI Linux应用程序简单地分析一张图片,并确定它的黑色图像(高对比度,低亮度)。到目前为止,我发现我可以使用ImageMagick获取图像的详细信息,但不知道如何使用这些数据......或者有更简单的解决方案吗?
convert original.jpeg -resize 1x1 1pixel-original.jpeg
然后调查一个像素的颜色,首先是
convert 1pixel-original.jpeg 1pixel-jpeg.txt
然后
cat 1pixel-jpeg.txt
#ImageMagick像素枚举:1,1,255,srgb
0,0:(130,113,108)#82716C srgb(130,113,108)
您也可以一次获得相同的结果:
convert original.jpeg -resize 1x1 txt: -
#ImageMagick像素枚举:1,1,255,srgb
0,0:(130,113,108)#82716C srgb(130,113,108)
通过这种方式,您可以在输入图像的原始色彩空间中获得avarage像素的值,你可以评估它的'亮度'(不过你定义了这个)。
你可以将图像转换为灰度,然后调整大小。这样你就可以得到灰度值来衡量'亮度':
convert original.jpeg -colorspace grey -resize 1x1 txt: -
#ImageMagick像素枚举:1,1,255,灰色
0,0:(117,117,117)#757575灰色(117,117,117)
您也可以将图像转换为HSB空间(色调,饱和度,亮度)并执行相同操作:
convert original.jpeg -colorspace hsb -resize 1x1 txt: -
#ImageMagick像素枚举:1,1,255,hsb
0 ,0:(61,62,134)#3D3E86 hsb(24.1138%,24.1764%,52.4941%)
您看到的'亮度'值(
134
,#86
或52.4941%
)可能是你想知道的。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?
解决方案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
or52.4941%
) is probably what you want to know.这篇关于如何确定图像是否黑暗? (高对比度,低亮度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!