您可以通过以下命令使用Imagemagick:
convert image.ext -colorspace RGB -format %c -depth 8 histogram:info:-|grep -i '#ff000'
Run Code Online (Sandbox Code Playgroud)
convert
程序会将图像转换为 8 位 RGB(CMYK 图像将给出虚假结果)并构建直方图,输出如下:
...
422: ( 0,255,255) #00FFFF cyan
126: ( 46,139, 87) #2E8B57 SeaGreen
...
Run Code Online (Sandbox Code Playgroud)
并且您需要过滤所需的颜色。