Implementation with recursive line segmentation