Added grayscale implementation of same algorithm