Fill area with nearest colour from boundary

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fill area with nearest colour from boundary

Post by fmw42 »

Snibgo: Terrific pepper processing!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fill area with nearest colour from boundary

Post by anthony »

snibgo... Are you sure your blurFill.bat doesn't 'leak' across boundaries?
This is the difference between a shepard's fill and a color diffusion

See... the 'leak' example on...
http://www.imagemagick.org/Usage/canvas ... ds_leakage

If color diffusion was used on that example only the areas between the lines will have a gradient. There will be no 'pink' color as you get distant.

Still I amazed your example came out so well, and shows the power of diffusion curves when you consider the original lines are stored as vector data, and not a pixel array.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fill area with nearest colour from boundary

Post by snibgo »

blurFill.bat can leak colours across boundaries, but doesn't noticeably in this example. This example has lines 3 pixels thick, and I used "-blur 0x1" so the blur doesn't noticeably leak for that distance.

The colour diffusion method carries more data about the lines than merely the colour at each point. Each line is: the Bezier geometry, and the colour at each point on the two sides (and a blur).

Fortunately for me, they rasterized the vector lines by a pair of lines of pixels, each 3 pixels thick. If they had been thinner, I could have used a smaller blur sigma (or radius) for the first few blurs.

Representing diffusion curves in pure raster format would need at least 7 channels: 3 colour channels for one side, 3 for the other side, and 1 for the blur.


Incidentally, on the speed of "-sparse-color Voronoi": the current IM implementation is brute-force. Faster algorithms are available, such as Fortune's algorithm, at the cost of much greater complexity.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fill area with nearest colour from boundary

Post by anthony »

I see the blurs are small enough that the 'diffusion' can't get past because of the the write mask (or restoration of edge pixels).

The fast voroni method I en-visualised was using a distance morphology much like... Constrained Distance
http://www.imagemagick.org/Usage/morpho ... nstrainted

It would using the new IMv7 write masks, that would allow the algorithm to understand that some pixels do not need to be re-calculated, and as such know when no more iterations is needed. The distance however would be stored in a separate channel, and color channels copied when shorter distances are found. Something like this is talked about in the Color Diffusion paper to generate an initial starting point, as it is very fast.

In IMv6 the write mask was accessible from the algorithm implementation level (it was done only at lower levels) so the algorithm did not know if the current pixel was in fact writable or not. It it did, many algorithms could speed up by skipping those pixels that can't change.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply