Apuleius
Apuleius

Reputation: 450

Draw gradient around closed cubic spline

For an image editing application i'm trying to draw a gradient around a closed natural cubic spline.
The spline is drawn according to the algorithm and code explained here.

The outcome should look like this (created with GIMP using lots of gaussian blur).

As i could not find any suitable algorithm to determine the distance from the spline, i tought of the following algorithm:

  1. Mark some key points on the spline
  2. Grow or enlarge these points with reference to the center of the closed spline
  3. Create a mesh of triangles between the inner points and the outer points. These triangles will have the inner vertexes black, and the outer vertexes white.

As you can see, this solution is quite complex (will probably have to rely on OpenGL) and hence suboptimal.

Can anybody come up with a simpler solution?
Thanks in advance.

Upvotes: 2

Views: 352

Answers (1)

MBo
MBo

Reputation: 80325

It seems you need to build distance transform map outside the spline. Some code for doing it. It is implemented in OpenCV library too.

Upvotes: 2

Related Questions