ImageMagick:我如何使用直方图结果? [英] ImageMagick: How can i work with histogram result?

查看:109
本文介绍了ImageMagick:我如何使用直方图结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获取图像的最现有颜色,并使用直方图功能显示它,如

im getting the most existing colors of an image and display it with the "histogram" funktion like

convert image.jpg  -scale 100x100 -gravity \
center -crop 50% -dither None -remap color_map.gif \
-format %c histogram:info:

    22: (  0,  0,  0) #000000 black
   881: (119,133,142) #77858E rgb(119,133,142)
   268: (186, 84, 29) #BA541D rgb(186,84,29)
   662: (212,212,212) #D4D4D4 grey83
    20: (244,203, 98) #F4CB62 rgb(244,203,98)
   647: (255,255,255) #FFFFFF white

我现在可以使用此输出吗?我想在我的数据库中保存最现有的颜色,但我现在不知道如何获得号码为881的颜色。
任何人都可以帮助我吗?

Ho can i work now with this output? i want to save the most existing color in my database, but i dont know how to get now only the color with the number 881. Can any one help me?

推荐答案

如果你想纯粹从shell(假设类似Bash的Unix环境)这样做,那么这样的东西就可以了:

If you want to do this purely from the shell (assuming Bash-like Unix environment), something like this would work:

convert image.jpg -scale 100x100 -gravity center \
  -crop 50% -dither None -remap color_map.gif \
  -format %c histogram:info: | sort | tail -n1 | \
  sed -e 's/.*\(#[0-9A-F]\+\).*/\1/'

从ImageMagick获取输出,对其进行排序,使最大颜色计数位于底部,仅取该行,然后从行中提取颜色十六进制。如果您的目标是获取十进制rgb值而不是十六进制,则可以调整sed正则表达式。

That takes the output from ImageMagick, sorts it so the largest color count is on the bottom, takes just that line, then extracts the color hex from the line. You can tweak the sed regex if your goal is to get the decimal rgb values instead of the hex.

因此对于您的示例图像,输出应该只是:

So for your example image, the output should be just:

#77858E

这篇关于ImageMagick:我如何使用直方图结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆