设置特定的图像亮度

问题描述 投票:2回答:2

我会在开始时将其解决:这可能是一个非常愚蠢的问题,它也可能属于不同的SE,所以请随时告诉我是否是这种情况。

我有一堆图像,它们是灰度和绿色通道的合并。有些图像比其他图像暗得多,而其余图像大致相同。

我想尽可能地“均匀化”图像集的亮度(它不一定是完美的)。

有谁知道是否有一个相当简单的方法来做到这一点?

这就是我目前正在考虑使用ImageMagick(一些bash伪代码和实际代码,因为我在OSX上使用CLI imagemagick,但其他解决方案没问题):

Step 1

读入我的“参考图像”集合,亮度/灰度级别我可以使用并获得平均灰度级别:

greyvals = ()
for file in an_array_of_image_files ; do
     # get array of grey values
     greyval=$(convert $file -colorspace Gray -format "%[mean]" info:)
     greyvals+=$greyval

# average the greyvals of the reference set through some mean function.

Step 2

这就是我的问题所在。有没有办法使图像变亮或变暗到指定的灰度级?

ImageMagick提供了modulate功能,但到目前为止我发现的例子需要一个百分比“增亮/变暗”,例如:

convert $file -modulate 200% ${file%.*}_bright.png

我完全吠叫了错误的树吗?


编辑

一些示例图片:

参考'足够亮'的图像:

enter image description here

一个示例'暗'图像:

enter image description here

直方图均衡图像 - 这看起来效果很好,但在某些区域引入了一些白色工件。 enter image description here

bash image-processing imagemagick image-manipulation
2个回答
1
投票

使用我的ImageMagick脚本,histmatch和matchimage,这里有一些结果使用你的两个图像。 ImageMagick 6.9.9.43 Q16和Mac OSX Sierra。

histmatch -c rgb reference.jpg dark.png dark_histmatch_rgb.png

enter image description here

histmatch -c gray reference.jpg dark.png dark_histmatch_gray.png

enter image description here

matchimage -c hsi dark.png reference.jpg dark_matchimage_hsi.png

enter image description here

matchimage -c ycbcr dark.png reference.jpg dark_matchimage_ycbcr.png

enter image description here


2
投票

使用ImageMagick 7我会考虑这种方法......

magick input.png -brightness-contrast %[fx:50-(mean*100)] output.png

这将调整每个输入图像,使整体平均亮度为50%。使用IM6,你可以使用这样的命令将所需的值转换为变量...

adjuster=`convert input.png -format %[fx:50-(mean*100)] info:`

然后在上面的IM7示例中使用该变量作为“-brightness-contrast”运算符的参数,就像这样...

convert input.png -brightness-contrast $adjuster output.png

我没有从* nix命令行测试过这个,但这个概念应该可行。

© www.soinside.com 2019 - 2024. All rights reserved.