lots of tweaks, added thresholding to transform input pixels.