Gamma correction is a well-known method used often for image enhancement, mainly to improve the luminance levels of dark and bright images. However, the enhancement level is highly affected by the gamma parameter used. In this paper, we propose a new iterative algorithm for automating the selection of the gamma value γ by maximizing the mean error between the pixel values. The experimental results (based on qualitative and quantitative assessments) prove the robustness of the proposed algorithm, particularly, when compared to some of the state-of-the-art methods.