墨水覆盖率结果的差异:ghostscript inkcov vs tiffsep 方法(vs APfill)
differences in ink coverage results: ghostscript inkcov vs tiffsep method (vs APfill)
在寻找一种从 pdf 文件中获取油墨覆盖率以对打印作业进行报价的方法时,我遇到了一个我无法理解的差异。
三种方法的油墨覆盖率结果存在差异。
在网上搜索我们发现了 APFill(试用版),它可以完成工作:测试文件给出以下结果:
我正在研究使用开源方法获得相同结果的方法。由于 APFill 使用 Ghostscript,我使用 inkcov 设备得到以下结果:
gs -o - -sDEVICE=inkcov testfile.pdf
结果如下:
Page 1
1.00000 1.00000 1.00000 0.76546 CMYK OK
这显然与 ApFill 的结果不同。考虑到测试文件不是几乎完整的 'rich black' 填写文档,Ghostscript 结果似乎也是错误的。
所以我进一步研究并使用 Ghostscript tiffsep 设备将 pdf 拆分为每个颜色分离的 tif 文件
gs -o test.tif -sDEVICE=tiffsep -r300x300 testfile.pdf
我在 python:
中使用 numpy 和 opencv 计算百分比像素值
img = cv2.imread('test(Cyan).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Magenta).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Yellow).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Black).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
结果如下:
0.5188357078732435
0.4992922045543696
0.5949687851445294
0.5271387924864341
与 APFill 结果大致相同。
所以我的问题是:GhostScript inkcov 设备是否只计算使用颜色的像素数量,而不是考虑单独像素中使用的颜色数量?还是我在监督什么?
感谢任何评论!
简单的答案是您使用了错误的设备 :-) 令人惊讶的是,有两种墨水覆盖率设备以不同的方式计算覆盖率。您正在使用 inkcov 设备,请尝试使用 ink_cov 设备。
对我来说,结果是:
GPL Ghostscript GIT PRERELEASE 9.28 (2019-04-04)
Copyright (C) 2019 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Processing pages 1 through 1.
Page 1
51.86353 49.92667 59.47390 52.62051 CMYK OK
这与您的 tiff32 结果非常接近。由于图像样本在设备像素上的放置方式不同,更改分辨率会产生细微的不同结果。
设备源代码在 ghostpdl/devices/gdevicov.c 中 'inkcov' 设备有一条评论说:
* columns 1 through 4 give the fraction of pixels containing
* c, m, y and black ink.
ink_cov 设备评论说:
/* cov_write_page2 gave ink coverage values not ratecoverage */
所以一个是包含 (CMYK) 着色剂的像素的百分比,另一个是整个页面上墨水的百分比。
在寻找一种从 pdf 文件中获取油墨覆盖率以对打印作业进行报价的方法时,我遇到了一个我无法理解的差异。 三种方法的油墨覆盖率结果存在差异。
在网上搜索我们发现了 APFill(试用版),它可以完成工作:测试文件给出以下结果:
我正在研究使用开源方法获得相同结果的方法。由于 APFill 使用 Ghostscript,我使用 inkcov 设备得到以下结果:
gs -o - -sDEVICE=inkcov testfile.pdf
结果如下:
Page 1
1.00000 1.00000 1.00000 0.76546 CMYK OK
这显然与 ApFill 的结果不同。考虑到测试文件不是几乎完整的 'rich black' 填写文档,Ghostscript 结果似乎也是错误的。
所以我进一步研究并使用 Ghostscript tiffsep 设备将 pdf 拆分为每个颜色分离的 tif 文件
gs -o test.tif -sDEVICE=tiffsep -r300x300 testfile.pdf
我在 python:
中使用 numpy 和 opencv 计算百分比像素值img = cv2.imread('test(Cyan).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Magenta).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Yellow).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
img = cv2.imread('test(Black).tif', 0)
inkcovIMG = img/np.full(img.shape, 255)
print (1-np.mean(inkcovIMG))
结果如下:
0.5188357078732435
0.4992922045543696
0.5949687851445294
0.5271387924864341
与 APFill 结果大致相同。
所以我的问题是:GhostScript inkcov 设备是否只计算使用颜色的像素数量,而不是考虑单独像素中使用的颜色数量?还是我在监督什么?
感谢任何评论!
简单的答案是您使用了错误的设备 :-) 令人惊讶的是,有两种墨水覆盖率设备以不同的方式计算覆盖率。您正在使用 inkcov 设备,请尝试使用 ink_cov 设备。
对我来说,结果是:
GPL Ghostscript GIT PRERELEASE 9.28 (2019-04-04)
Copyright (C) 2019 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Processing pages 1 through 1.
Page 1
51.86353 49.92667 59.47390 52.62051 CMYK OK
这与您的 tiff32 结果非常接近。由于图像样本在设备像素上的放置方式不同,更改分辨率会产生细微的不同结果。
设备源代码在 ghostpdl/devices/gdevicov.c 中 'inkcov' 设备有一条评论说:
* columns 1 through 4 give the fraction of pixels containing
* c, m, y and black ink.
ink_cov 设备评论说:
/* cov_write_page2 gave ink coverage values not ratecoverage */
所以一个是包含 (CMYK) 着色剂的像素的百分比,另一个是整个页面上墨水的百分比。