After converting the two value graph to signed distance field, you can achieve a smooth amplification with bilinear interpolation.
Defined:
To the foreground of distance field: The distance from each point to the nearest former attraction.
Distance field to the background: distance from each point to the nearest background attraction.
Then: signed Distance field = to the background of the distance field-to the foreground of the distance field.
Note: It is best to calculate signed distance field strictly as defined above. See some of the blog post to extract the outline points, and then calculate the points to the nearest contour point distance, and if this point is the former attractions will calculate the distance plus + number, if this point is the background point will calculate the distance plus-number. It does get a signed distance field, but obviously the calculated signed distance field is not the same as the result calculated in strict accordance with the definition above.
After calculating the signed distance field by standard definition, the contour threshold should be 0.5, that is, the pixel in signed distance field that is greater than or equal to 0.5 is restored as the foreground.
When I actually stored it, I asked for it. Signed distance field maximum Max and Min min, then maps Signeddis to [0,1] through (signeddis-min)/(Max-min), and maps the contour threshold 0.5 to ( 0.5-min)/(Max-min), a signed distance field with a value between [0,1] is obtained, and its outline threshold is (0.5-min)/(Max-min).
To generate an algorithm for signed distance field, I began to find a Saito algorithm in this blog post (http://blog.csdn.net/tianwaifeimao/article/details/45078661), It can improve the computational efficiency by using the properties of distance squared on X and y, but it is much faster than the brute force algorithm, although the linear complexity is not fully achieved. The correctness of the algorithm is easy to see, the implementation of the measured, and no problem.
Later on the Internet to find an algorithm called 8ssedt (see: Http://www.codersnotes.com/algorithms/signed-distance-fields), blog post to the paper link cannot open, but give the source code to download, Code is very short to see, with the shortest path algorithm the same idea, the structure of the problem itself did a very clever optimization, to achieve the linear complexity. (Note: The first step of the Saito algorithm is to use the idea of the 8SSEDT algorithm to optimize the calculation of the points at the nearest spot in the bank).
The 8ssedt algorithm code is as follows (from: Http://www.codersnotes.com/algorithms/signed-distance-fields):
#include "sdl/sdl.h" #include <math.h> #define WIDTH 256#define HEIGHT 256struct point{int DX, dy;int distsq () const {return dx*dx + Dy*dy;}}; struct grid{point grid[height][width];}; Point inside = {0, 0}; Point empty = {9999, 9999}; Grid Grid1, Grid2; Point Get (Grid &g, int x, int y) {//optimization:you can skip the Edge check code if you make your Grid//has a 1 -pixel gutter.if (x >= 0 && y >= 0 && x < WIDTH && y < HEIGHT) return G.grid[y][x];el Sereturn empty;} void Put (Grid &g, int x, int y, const point &p) {g.grid[y][x] = p;} void Compare (Grid &g, point &p, int x, int y, int offsetx, int. offsety) {Point other = Get (g, X+offsetx, Y+OFFSE ty); Other.dx + = Offsetx;other.dy + = Offsety;if (other. DISTSQ () < P.DISTSQ ()) p = other;} void Generatesdf (Grid &g) {//Pass 0for (int y=0;ySigned Distance field algorithm