如何制作Photoshop描边效果?

发布于 2024-07-07 20:14:06 字数 650 浏览 7 评论 0原文

我正在寻找一种以编程方式重新创建以下效果的方法:

提供输入图像:
输入 http://www.shiny.co.il/shooshx/ConeCarv/q_input .png

我想迭代应用“描边”效果。
第一步如下所示:
步骤 1 http://www.shiny.co.il/shooshx/ConeCarv/ q_step1.png

第二步是这样的:
替代文本 http://www.shiny.co.il/shooshx/ConeCarv/ q_step2.png

等等。

我认为这将涉及某种边缘检测,然后以某种方式跟踪边缘。
是否有已知的算法可以有效且稳健地执行此操作?

I'm looking for a way to programmatically recreate the following effect:

Give an input image:
input http://www.shiny.co.il/shooshx/ConeCarv/q_input.png

I want to iteratively apply the "stroke" effect.
The first step looks like this:
step 1 http://www.shiny.co.il/shooshx/ConeCarv/q_step1.png

The second step like this:
alt text http://www.shiny.co.il/shooshx/ConeCarv/q_step2.png

And so on.

I assume this will involves some kind of edge detection and then tracing the edge somehow.
Is there a known algorithm to do this in an efficient and robust way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场春暖 2024-07-14 20:14:06

基本上,根据此线程:

获取像素周围的 3x3 邻域,对 Alpha 通道进行阈值处理,然后查看该像素周围的 8 个像素中是否有任何一个具有与其不同的 Alpha 值。 如果是的话画一个
以像素为中心的给定半径的圆。 要执行内部/外部操作,请通过阈值 Alpha 通道进行调制(否定执行另一侧)。 如果圆半径大于像素(很可能是),则必须设置更大的邻域阈值。


这是使用灰度形态学运算实现的。 这也是用于扩展/收缩选择的相同技术。 基本上,要描边选区(或 Alpha 通道)的中心,首先要制作选区的两个单独副本。 第一个选择将按笔画的半径扩大,而第二个选择将缩小。 然后,通过从第一个选择中减去第二个选择来获得笔画的不透明度。

为了进行内部和外部笔画,您需要收缩/扩展两倍半径,并减去与原始选择相交的部分。

需要注意的是,最通用的形态学算法需要 O(m*n) 次运算,其中 m 是图像的像素数量,n 是“结构元素”中的元素数量。 然而,对于某些特殊情况,这可以优化为 O(m) 操作(例如,如果结构元素是矩形或菱形)。

Basically, a custom algorithm would be, according to this thread:

Take the 3x3 neighborhood around a pixel, threshold the alpha channel, and then see if any of the 8 pixels around the pixel has a different alpha value from it. If so paint a
circle of a given radius with center at the pixel. To do inside/outside, modulate by the thresholded alpha channel (negate to do the other side). You'll have to threshold a larger neighborhood if the circle radius is larger than a pixel (which it probably is).


This is implemented using gray-scale morphological operations. This is also the same technique used to expand/contract selections. Basically, to stroke the center of a selection (or an alpha channel), what one would do is to first make two separate copies of the selection. The first selection would be expanded by the radius of the stroke, whereas the second would be contracted. The opacity of the stroke would then be obtained by subtracting the second selection from the first.

In order to do inside and outside strokes you would contract/expand by twice the radius and subtract the parts that intersect with the original selection.

It should be noted that the most general morphological algorithm requires O(m*n) operations, where m is the number of pixels of the image and n is the number of elements in the "structuring element". However, for certain special cases, this can be optimized to O(m) operations (e.g. if the structuring element is a rectangle or a diamond).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文