Thinning algorithm.

Signed-off-by: CyberZHG <cyberzhg@gmail.com>