The origin of the microscopic inhomogeneities in InxGa12xAs layers grown on GaAs by molecular beam epitaxy is analyzed through the optical absorption spectra near the band gap. It is seen that, for relaxed thick layers of about 2.8 mm, composition inhomogeneities are responsible for the band edge smoothing into the whole compositional range (0.05,x,0.8). On the other hand, in thin enough layers strain inhomogeneities are dominant. This evolution in line with layer thickness is due to the atomic diffusion at the surface during growth, induced by the strain inhomogeneities that arise from stress relaxation. In consequence, the strain variations present in the layer are converted into composition variations during growth. This process is energetically favorable as it diminishes elastic energy. An additional support to this hypothesis is given by a clear proportionality between the magnitude of the composition variations and the mean strain.