如何从命令行将图像转换为卡通?

mar*_*nuy 7 command-line gimp photoshop graphics

我想仅使用命令行从照片中创建这种卡通效果。

想要的效果示例:

  • 在此处输入图片说明

你能描述一下实现这个卡通效果的过程或给出一些提示吗?

信息:

Rin*_*ind 9

我找到了一个用于 imagemagick的 bash脚本,由 Fred Weinhaus 完成。他的脚本仅可免费用于非商业用途。

命令行用法:

USAGE: cartoon [-p pattern] [-n numlevels] [-m method] [-e edgeamount] 
[-b brightness] [-s saturation] infile outfile

USAGE: cartoon [-h or -help]

-p ... pattern ...... segmentation pattern (shape); 0<=integer<=100;
..................... default=70
-n ... numlevels .... number of desired segmentation levels; integer>=2;
..................... default=6
-m ... method ....... edge method; 1 or 2; default=1
-e ... edgeamount ... amount of edges; float>=0; default=4
-b ... brightness ... brightness of cartoon; integer>=0; default=100
-s ... saturation ... saturation of cartoon; integer>=0; default=150

PURPOSE: To create a cartoon-like appearance to an image.
Run Code Online (Sandbox Code Playgroud)

(更多关于网站本身。)脚本的作用......

(Optionally) applies a median filter to the image
Reduces the number of colors in the filtered image
Converts the original image to grayscale
(Optionally) applies a median filter to the grayscale image
Applies a gradient edge detector to the grayscale image
Thresholds the edge image to binary
Composites the edge image with the color reduced image
Run Code Online (Sandbox Code Playgroud)

他的网站上有示例,但这些示例与您的示例相距甚远。您可能需要调整设置才能显示图像的外观。

  • 完美的。应该被接受的答案。 (2认同)

Tak*_*kat 5

由于您可能已经从各种图像处理解决方案中发现了分色过滤器的卡通,可能需要对原始来源进行大量调整,然后才能获得与您的示例类似的结果。

从命令行运行的两种解决方案可能会为您提供与您的示例接近的结果,但我们得到的结果仍然在很大程度上取决于所使用的源图像。

图像魔术师

使用convertmogrify工具,我们可以将-paint用于平面卡通风格的过滤器应用到我们的源代码中:

convert -paint <strength> <source> <output>
Run Code Online (Sandbox Code Playgroud)

替换<strength>为整数以指定画笔大小。越小,保留的细节就越多。在您的示例中,我4对以下结果使用了强度:

在此处输入图片说明

跟踪到矢量图形

通过使用例如 Inkscape将位图追踪到矢量图形,可以获得比位图操作更好的结果。然后,我们还可以添加笔触或调整生成的颜色以更好地满足我们的需求。

可以使用autotrace安装命令行跟踪器(遗憾的是,此软件包仅在 Ubuntu 18.04 或更早版本的存储库中)。

许多选项可以调整使用自动跟踪获得的结果。下面的示例是使用这些选项生成的:

autotrace -color-count 6 -filter-iterations 8 -remove-adjacent-corners -output-format svg input.png > output.svg
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明