improved algorithm for determining black level