orzzzjq/Parallel-Banding-Algorithm-plus

How do I generate a distance transform diagram similar to the one in README.MD?

Closed this issue · 2 comments

Hello, I'd like to enter a two-value image (this one in the middle of the image below) and generate its distance transform diagram (the one on the far right below), what do I need to do?
img

void generateRandomPoints(int width, int height, int nPoints)
{
int tx, ty;
randinit(0);
for (int i = 0; i < width * height * 2ULL; i++)
inputVoronoi[i] = MARKER;
for (int i = 0; i < nPoints; i++)
{
do {
tx = int(random() * width);
ty = int(random() * height);
} while (inputVoronoi[(ty * width + tx) * 2] != MARKER);
inputVoronoi[(ty * width + tx) * 2 ] = tx;
inputVoronoi[(ty * width + tx) * 2 + 1] = ty;
inputPoints[i * 2 ] = tx;
inputPoints[i * 2 + 1] = ty;
}
}

First, modify this function and set the value of the front points (in the image, the white pixels) to be their coordinate (tx, ty). And leave the other points to be MARKER. Then run the program you can get the Voronoi diagram. Some details can be found here:

// Compute 2D Voronoi diagram
// Input: a 2D texture. Each pixel is represented as two "short" integer.
// For each site at (x, y), the pixel at coordinate (x, y) should contain
// the pair (x, y). Pixels that are not sites should contain the pair (MARKER, MARKER)
// Output: 2 2D texture. Each pixel is represented as two "short" integer
// refering to its nearest site.
// See original paper for the effect of the three parameters:
// phase1Band, phase2Band, phase3Band
// Parameters must divide textureSize
extern "C" void pba2DVoronoiDiagram(short *input, short *output, int phase1Band,
int phase2Band, int phase3Band);

After calling this function pba2DCompute(), pbaTextures[1] will store the coordinate of the closest front point, then you can write a simple kernel to compute the distance.

Thank you, I probably understand how to generate a dt diagram.