Anti-aliased stroked mask using distance transform

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Anti-aliased stroked mask using distance transform

Post by thevinn »

From a binary mask it is possible to generate an anti-aliased stroke using an exact distance transform:

Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Anti-aliased stroked mask using distance transform

Post by anthony »

Strokes in IM are anti-aliased. At least in my experience.

Distance transform however requires the anti-alising pixels converted to 'distance' (below 'unit' distance, default=100 per pixel width) before the main distance function runs.

For details see... Distance with an Anti-Aliased Shape
http://www.imagemagick.org/Usage/morpho ... anti-alias

And no there is no internal function for this as yet. PS: anti-aliasing pixels may have been generated in a linear colorspace, or a gamma/sRGB colorspace, which many need to be corrected. This was not looked at when I wrote that set of examples.
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: Anti-aliased stroked mask using distance transform

Post by thevinn »

anthony wrote:Distance transform however requires the anti-alising pixels converted to 'distance' (below 'unit' distance, default=100 per pixel width) before the main distance function runs.
With the new information regarding Outer Glow and what not, to reproduce Photoshop's "Stroke" effect, it suffices merely to perform the same morphological dilation as in Drop Shadow, and skip the Blur step (i.e. spread == 100%).
And no there is no internal function for this as yet. PS: anti-aliasing pixels may have been generated in a linear colorspace
Photoshop uses linear color space for RGB when performing internal calculations (like anti-aliasing).
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Anti-aliased stroked mask using distance transform

Post by anthony »

I am not disagreeing with you. But you need to convert some of the distance measurements into semi-transparent anti-aliasing pixels.

I have converted from anti-aliasing pixels to distances,
http://www.imagemagick.org/Usage/morpho ... anti-alias
But I have not done the reverse.

WARNING: colors may be in non-linear sRGB colorspace, but alpha should always be linear.
Of course compositions involving anti-aliasing pixels should be performed in a linear colorspace too.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply