Optimized contrast enhancement for real-time image and video dehazing