WIP: Automatically calculate the number of sampels to use

When generating a KNN tree, using as many good
samples as makes for a balanced tree can improve
robustness.  This patch dynamically calculates
the minimum number of samples that can be extracted
from a label map within the desired threshold.