【发布时间】:2019-05-30 12:41:05
【问题描述】:
我需要转换图像以进行对象检测。我从具有多个多边形的 svg 图像开始。示例:
<svg ...>
<rect width = "100%" height = "100%" fill = "rgb(0,0,0)" />
<polygon points="..." fill="rgb(221,221,221)" fill-opacity="1.0" />
<polygon points="..." fill="rgb(100,100,100)" fill-opacity="0.5" />
</svg>
结果是黑色背景,对象 A 的颜色为 rgb(221,221,221),对象 B 的颜色为 rgb(50,50,50),并且两个对象重叠的任何地方都是 rgb(160,160,160)。检测算法(无法修改)通过像素值确定对象。
我已使用inkscape、svgr-convert 或ImageMagikk 成功地将svg 转换为png。但是这些 png 图像的边缘总是很模糊,这会干扰我的对象检测。
有没有什么方法可以让边缘变得清晰? This image shows the conversion adding blurred pixels with incorrect values. I have zoomed into an edge to make it obvious.
编辑:完整图像示例
<svg viewBox="17.874 6.66874 74.0131 70.817" xmlns="http://www.w3.org/2000/svg">
<rect width = "100%" height = "100%" fill="black" fill-opacity="1.000000" stroke="black" stroke-opacity="1.000000" stroke-width ="0.000000"/>
<polygon points="66.499391,34.862972 35.730400,51.495089 68.667463,64.499553 " fill="rgb(221,221,221)" fill-opacity="1.000000" />
<polygon points="47.613765,49.254424 23.219703,52.458598 47.246912,50.965952 48.078815,51.599703 49.620943,52.471096 62.516253,65.471290 65.077318,43.877861 51.086443,12.014429 34.861708,20.532821 " fill="rgb(100,100,100)" fill-opacity="0.500000" />
</svg>
【问题讨论】:
-
用 ImageMagick 试试
convert +antialias input.svg output.png -
抗锯齿并没有解决这个问题,它似乎确实在一定程度上降低了效果
-
也许你可以添加一个完整的、简单的 SVG 来测试,拜托。另请显示您的 ImageMagick 版本,即
identify -version的输出 -
版本:ImageMagick 7.0.8-22 Q16 x86_64 2018-12-31 imagemagick.org 版权所有:© 1999-2019 ImageMagick Studio LLC 许可:imagemagick.org/script/license.php 功能:密码 DPC HDRI 模块代表(内置- in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff webp xml zlib
-
我在想
-interpolate integer会是解决方案,但它也不能解决问题。
标签: svg imagemagick png inkscape librsvg