Line detection PR #2 follow-up.

This PR includes #2 rebased on top of current HEAD + a commit that cleans up the code and adds an improved adaptive thresholding routine.
If we can count f1 score for each combination of input params on a known dataset then we can adjust params to achieve the best score possible.