orzzzjq / Parallel-Banding-Algorithm-plus

Compute the exact Euclidean Distance Transform and Voronoi Diagram for 2D and 3D binary images using the GPU.
https://www.comp.nus.edu.sg/~tants/pba.html
MIT License
73 stars 8 forks source link

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

Closed Liber-coder closed 3 years ago

Liber-coder commented 3 years ago

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

orzzzjq commented 3 years ago

https://github.com/orzzzjq/Parallel-Banding-Algorithm-plus/blob/2f58720302c3478d4367b21268dfbb263b46c4d2/pba-plus-2D/main.cpp#L87-L109

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: https://github.com/orzzzjq/Parallel-Banding-Algorithm-plus/blob/2f58720302c3478d4367b21268dfbb263b46c4d2/pba-plus-2D/pba/pba2D.h#L50-L60

https://github.com/orzzzjq/Parallel-Banding-Algorithm-plus/blob/2f58720302c3478d4367b21268dfbb263b46c4d2/pba-plus-2D/pba/pba2DHost.cu#L162

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.

Liber-coder commented 3 years ago

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