Photoshop "Outer Glow" Technique: Soft?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Photoshop "Outer Glow" Technique: Soft?

Post by thevinn »

I'm working on implementing Photoshop Layer Styles in my MIT licensed project:

https://github.com/vinniefalco/LayerEffects

After a lot of study and searching I figured out that the distance transform plays a key role in implementing almost all the styles. You can see clear evidence of the distance transform by turning on the "Stroke" layer style, setting the fill type to Gradient, and choosing "Shape Burst" for the style.

If you set the Outer Glow style to the "Precise" technique it also shows direct evidence of a canonical distance transform.

But what is the algorithm used for the "Soft" technique? It does not look like a distance transform. At least, not directly. There seems to be some sort of blur. But its not a blur because I try blurring the mask using similar settings, and doing a difference calculation on the outer glow versus my blurred mask and there are some small pixel differences at various radii.

Can someone please point me in a direction for implementing the "Soft" technique of Photoshop's Outer Glow filter?

Thanks
Last edited by thevinn on 2012-12-19T09:23:28-07:00, edited 1 time in total.
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Re: Photoshop "Outer Glow" Technique: Soft?

Post by thevinn »

Could the Fast Marching algorithm be part of a possible solution?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photoshop "Outer Glow" Technique: Soft?

Post by anthony »

Your link is 404 (broken). So it is hard to discuss.

----
There are two basic ways of doing a distance transform.

One is to simply blur and transform the resulting gradient appropriately.
http://www.imagemagick.org/Usage/fonts/#neon
http://www.imagemagick.org/Usage/color_mods/#clut_alpha

But this has problems with blunting 'sharp points' and 'corners', while fulling in small gaps and indents in the shape.
See feathering using Blur...
http://www.imagemagick.org/Usage/blur/#feathering
Image Image Image Image Image

Blur also produces a non-linear sigmoidal-like result. This may need to be fixed to get a more linear 'distance' result. Probably using something like a +sigmoidal-contrast function.
http://www.imagemagick.org/Usage/color_mods/#sigmoidal

Or using a VERY large sigma value for the blur with a radius limit to produce 'linear blurs' (for example -blur 10x65535). A technique developed by Fred Weinhouse, though that produces a square or pyramid like 'Chebyshev' linear distance gradient. It is also equivalent to using 'Average Filtering using Shape Kernels' which does give more control over the distance blurring.
http://www.imagemagick.org/Usage/convolve/#mean

----
The other method is a true linear distance function
http://www.imagemagick.org/Usage/morphology/#distance

Perhaps with anti-aliasing handling
http://www.imagemagick.org/Usage/morpho ... anti-alias

But can produce some sharp ridges from corners
http://www.imagemagick.org/Usage/thumbnails/#soft_edges
Image
especially in aliased (boolean) shapes (see bitmap feathering in)
http://www.imagemagick.org/Usage/morpho ... ce_feather
Image Image Image

----
My feeling is that some strange mix of the two may be needed, to produce a feathering or distance gradient that does not 'change the border', but also does not produce internal ridges.

If you do experiment, please report your results. I am sure a number of people would like to comment on things as you go.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Re: Photoshop "Outer Glow" Technique: Soft?

Post by thevinn »

Sorry for the delay, I fixed the link.
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Re: Photoshop "Outer Glow" Technique: Soft?

Post by thevinn »

Upon much research, and consulting with other individuals, my latest theory is that Photoshop's "Outer Glow, Softer" algorithm is as follows:

1) Apply morphological dilation to the mask, dilationSize = (outerGlowSize * spread), output 8-bit alpha

2) Apply two pass box blur, equivalent radius = outerGlowSize - dilationSize, output 32-bit signed integers with 8-bit fractional precision
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photoshop "Outer Glow" Technique: Soft?

Post by anthony »

On review there is a thrid posiblity. using a 'diffusion curve' between a fixed outisde and inside shape. this will be sharp as it approaches sharp points (as in a true distance gradient), but become smoother away from those points (as in a blur).

See the related (but not quite the same as it 'leaks'), shepards sparse-color method
Sparse Color as a Fill Operator
http://www.imagemagick.org/Usage/canvas/#sparse_fill
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Re: Photoshop "Outer Glow" Technique: Soft?

Post by thevinn »

anthony wrote:On review there is a thrid posiblity. using a 'diffusion curve' between a fixed outisde and inside shape. this will be sharp as it approaches sharp points (as in a true distance gradient), but become smoother away from those points (as in a blur).
Isn't this just the same thing? Morphological dilate produces the "outer" shape, and then a box blur smooths everything out.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Photoshop "Outer Glow" Technique: Soft?

Post by anthony »

Diffusion vs Blurring...

All blurs will round off sharp points. A Box blur will preserve a orthogonally (axis) aligned corner, but not other points.
That is blur can change the values of the 'edges' of the objects in a globally unrestricted way. Thus the need to post-process to try and restore the correct 'edge values' that is wanted.

Diffusion (or even shepards) does not change the 'edge' values, just work out the appropriate blurring of all the values between these points (generally in some iterative fashion) to produce a smooth gradient. You could say it is a bounds limited blurring.

Shepard's Interpolation is similar but blurs toward a 'average color' at a distance from the bounds. In effect.. if you have two areas, the boundary values of one area will 'leak' into the inside of the other area. (This is how gravitational fields behave, and why it has a cumulative effect with large masses).

True Diffusion however will not allow values to be 'seen' though any boundaries of fixed values. That is the values can not leak from one area into another area. (Electric Fields behave like this) Only if there is a path between the point being blurred and some fixed edge will that edge has an effect, though if that path is a convoluted curve it will have very minimal effect, even if (as the crow flys) the point in question is rather close to that 'edge' (though some other edge of fixed points).


NOTE what is often ignored in diffusion is that you can also have 'insulating edges' That is fixed edges that does not allow leakage, but does not contribute to the final values of nearby non-fixed values. That is they insulate between two areas without effecting those areas. That is something that is VERY hard to do calculate.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply