fixed averaging for gray scale values