In this paper, we shall propose a novel image-hiding scheme. Our new scheme classifies the host image pixels into two groups of pixels according to the pixel values. For each group of pixels, the corresponding secret pixel values go through an optimal substitution process and are transformed into other pixel values by following the dynamic programming strategy. Then, we can embed the transformed pixel values in the host pixels by using the modulus functions and obtain the stego-image. Extensive experimental results demonstrate that our new method is capable of offering better stego-image quality than a number of well-accepted schemes.