Gray -= minval;
Gray /= maxval - minval;