java - ImageMagick 命令缓慢问题

标签 java linux ubuntu image-processing imagemagick

我在我的 Web 应用程序中使用 ImageMagick 进行一些图像处理(在 Ubuntu OS 中使用 Java 作为后端),以从图像中识别 CMYK 颜色。

原始图片:

enter image description here

整个图像的过程如下:

首先,我在 CMYK 灰度中分离四张图像:

convert IMG_1732.jpg -colorspace CMYK -negate -separate IMG_1732-sep.jpg

四张图片的结果如下:

图 1:

enter image description here

图 2:

enter image description here

图 3:

enter image description here

图 4:

enter image description here

然后我执行以下命令将每个灰度图像转换为 C、M、Y、K 彩色图像:

convert IMG_1732-sep-0.jpg -channel C -combine IMG_1732-sep-00.jpg

结果 1:

enter image description here

convert IMG_1732-sep-1.jpg -channel M -combine IMG_1732-sep-11.jpg

结果 2:

enter image description here

convert IMG_1732-sep-2.jpg -channel Y -combine IMG_1732-sep-22.jpg

结果 3:

enter image description here

convert IMG_1732-sep-3.jpg -channel K -combine IMG_1732-sep-33.jpg

结果 4:

enter image description here

问题是,它花费了太多时间,图像大小超过 2-3 MB。此外,还会消耗更多的 RAM 和 CPU。

  • 我该如何优化它? ImageMagick 中是否还有其他选项或 还有其他方法吗?
  • 我如何知道原始图像中可用的青色百分比?与洋红色、黄色和黑色相同吗?可能吗?

最佳答案

如果您的数字 4 是与 CMYK 分离的 channel ,则不可能有彩色图像。所有单个 channel 都是灰度的。我也无法重现您的确切颜色。因此,要么图像不同或发生变化,要么您没有告诉我们您所有的处理步骤。

类似于 Mark Setchell 的命令,我可以在一个命令行中编写您的命令,并获得大约 0.63 秒的处理时间。

time convert image.jpg -colorspace cmyk -negate -separate \
\( -clone 0 -channel C -combine +write C.jpg \) \
\( -clone 1 -channel M -combine +write M.jpg \) \
\( -clone 2 -channel Y -combine +write Y.jpg \) \
\( -clone 3 -channel K -combine +write K.jpg \) \
null:

0.626s


C.jpg enter image description here

M.jpg enter image description here

Y.jpg enter image description here

K.jpg enter image description here

如果您想要较小的文件大小,请在 +write 之前的每个括号中的命令中添加 -quality XX。或者找到一些 JPG 优化器工具来对每个结果图像进行后期处理。 Imagemagick 使用 libjpeg,它可能不是最高效的压缩器。我检查过,你的输入和我所有的输出结果都使用 -quality 95。

如果我包含 -normalize 以增加对比度,我可以更接近您的结果,但处理时间会增加到大约 0.83 秒。

convert image.jpg -colorspace cmyk -negate -separate -normalize \
\( -clone 0 -channel C -combine +write C.jpg \) \
\( -clone 1 -channel M -combine +write M.jpg \) \
\( -clone 2 -channel Y -combine +write Y.jpg \) \
\( -clone 3 -channel K -combine +write K.jpg \) \
null:

enter image description here

enter image description here

enter image description here

enter image description here

我如何知道原始图像中可用青色的百分比?与洋红色、黄色和黑色相同吗?

convert image.jpg -colorspace CMYK -format "%[fx:mean.c], %[fx:mean.m], %[fx:mean.y], %[fx:mean.k]\n" info: 

输出: 0.0606194、0.0598201、0.0300933、0.0748128

这些值是 0 到 1 范围内的分数。对于百分比,将每个平均值乘以 100。请注意末尾需要冒号。

关于java - ImageMagick 命令缓慢问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52070639/

相关文章:

linux - 在 ubuntu 18.04 上更新后无法打开 libmpfr.so.4

Java:如何使容器的Jscrollpane背景不透明? (即透明)

java - 如何在抽象父类(super class)中使用子类的方法

linux - 在 shell 中显示文件名、日期、大小

在 Linux 中编译 Windows C 控制台应用程序

ubuntu - 为什么 Nmap 使用超出范围的源端口号?

java - 在 Android Studio 中添加库依赖

java - 对于多人游戏场景,如何在客户端之间序列化更新消息?

android - Android 和 Linux (RPi) 之间的蓝牙连接在第一次写入操作时丢失

linux - 将 perl 模块复制到其他机器