Voronoi' Morphology Distance method

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?".
Post Reply
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Voronoi' Morphology Distance method

Post by 3DTOPO »

Greetings,

I read with interest about the new Voronoi' Morphology Distance method that "will fill in holes using the nearest non-transparent edge pixel".

Can someone please show me an example how to use this feature?

Thank you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Voronoi' Morphology Distance method

Post by fmw42 »

see http://www.imagemagick.org/Usage/canvas/#sparse_fill

It -sparse-color just looks for fully transparent pixels and replaces them with one of the appropriate interpolation methods, shepars, voronoi, etc

you can just replace shepards with voronoi.

I use voronoi in my script, stainedglass, at the link below. So you can see from the script how I did that. It has been a while since I wrote that so I am a bit fuzzy on it, but it mostly follows Anthony's example above. I just created a repeated pattern of individual pixels sampled from the image onto a transparent image background and then used -sparse-color voronoi to fill in the transparent values.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Voronoi' Morphology Distance method

Post by anthony »

As fred pointed out, Voroni is a sparse color method, and while related to a Morphology Distance Gradient, it is not the same.

It is also a 'point' solution where it looks for the nearest colored point that was given in a list. The provided image only provides a 'base canvas' on which it works, and which it will overwrite (unless a write or clipping mask was set).

You can however convert the edges of an image into a 'point list' for voronoi point filling!
See the 'shepards fill' example in...
http://www.imagemagick.org/Usage/canvas/#sparse_fill
The key is to only generate a list of edge pixels so that the 'point list' is kept to a minimum.
(This is something I would have liked to build into IM but never got around to it)


I did make a note morphology distance function (which their is half a dozen distance metric for) can be used to generate a 'fast voronoi' fill method. however this requires that while the distance function is generated in one channel (typically a negated alpha channel), the values in the other channels (color) of any newly discovered the 'nearest pixel' also need to be copied at the same time.

It is a tricky solution but works without needing a point list, and for any number of pixels, is just two passes through the image just as the distance function does, instead of the current one pass with a list. Also you can make selection
of different and simpler distance metrics (like a Knights Move, or Octagon) than just Eucliedien.

It is part of first stage in a true 'diffusion hole filling' technique, which understands boundary conditions, unlike a 'shepards fill' technique that is already available, and even provides a faster blurred image stack alternative.

It is a variation that requires some addition programming which I have not had the time to make.

I have however attempted tried to implement in other ways as quick experiments (in hole filling), quite some time ago, but nothing really useful came from it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply