thresholding: Fix image data problem. Add comments. Refactor test case