fixed problems for gray scale images.