Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 尝试在PNG周围添加笔划,可以改进吗?_Image Processing_Imagemagick - Fatal编程技术网

Image processing 尝试在PNG周围添加笔划,可以改进吗?

Image processing 尝试在PNG周围添加笔划,可以改进吗?,image-processing,imagemagick,Image Processing,Imagemagick,我正试图找到一种好方法,在大量png文件中添加一个3倍的白色笔划,有效地使它们看起来像“贴纸”。我有一些示例代码做得不错,但我似乎无法正确地裁剪。此外,笔划看起来有点像素化,我想知道是否有可能获得更干净的边缘 我做了一系列的互联网搜索,找到了一些示例代码,对其进行了调整,得到了一些与我所寻找的几乎相似的东西。图像始终是PNG,因此我从命令行查看了inkscape/gimp之类的东西,但意识到我应该能够从终端使用convert convert in.png \ \( -clone 0 -alpha

我正试图找到一种好方法,在大量png文件中添加一个3倍的白色笔划,有效地使它们看起来像“贴纸”。我有一些示例代码做得不错,但我似乎无法正确地裁剪。此外,笔划看起来有点像素化,我想知道是否有可能获得更干净的边缘

我做了一系列的互联网搜索,找到了一些示例代码,对其进行了调整,得到了一些与我所寻找的几乎相似的东西。图像始终是PNG,因此我从命令行查看了inkscape/gimp之类的东西,但意识到我应该能够从终端使用
convert

convert in.png \
\( -clone 0 -alpha extract -threshold 0 \) \
\( -clone 1 -blur 10x65000 -threshold 0 \) \
\( -clone 2 -fill red -opaque white \) \
\( -clone 3 -clone 0 -clone 1 -alpha off -compose over -composite \) \
-delete 0,1,3 +swap -alpha off -compose copy_opacity -composite \
out.png
在:

输出:

理想情况下:
您的主要问题是,您的对象和图像侧面之间没有足够的空间。您只需要添加具有透明度的图像,然后删除多余的图像

在ImageMagick 6中,这应该满足您的要求


对于ImageMagick 7,将convert替换为magick

如果是在类Unix系统上,您可能会对我的bash ImageMagick脚本contour感兴趣

用圆盘10代替菱形10可以获得更好的结果


这真是太接近了。实际上我使用了这个,只是将形态从菱形:10改为八角形:4,看起来更好一些(你可以在你的图片中看到左下角看起来有点时髦)。请随意修改它。请注意我的答案顶部的编辑。我修改了我的答案以显示相同的结果,但使用了disk:10而不是diamond:10
1) read the input
2) add a larger border than you need to add
3) extract the alpha channel from the input and dilate it by the amount of border (in this case 10)
4) copy the previous image and color the white as red and the black as transparent
5) composite the original over the red/transparent image
6) delete the original and the red/transparent image
7) swap the composite with the dilated alpha channel and put the dilated alpha channel into the alpha channel of the previous image
8) trim the excess transparency from the border padding
9) save to output

convert img.png \
-bordercolor none -border 20 \
\( -clone 0 -alpha extract -morphology dilate diamond:10 \) \
\( -clone 1 -fuzz 30% -fill red -opaque white -fill none -opaque black \) \
\( -clone 2,0 -compose over -composite \) \
-delete 0,2 \
+swap -alpha off -compose copy_opacity -composite \
-trim +repage \
result.png