Extensive comments added to code, adaptive thresholding of source image