updated threshold and use grayscale