  We present a method to model optical images of galaxies using Expectation
Maximization Principal Components Analysis (EMPCA). The method relies on the
data alone and does not assume any pre-established model or fitting formula. It
preserves the statistical properties of the sample, minimizing possible biases.
  The precision of the reconstructions appears to be suited for photometric,
morphological and weak lensing analysis, as well as the realization of mock
astronomical images. Here, we put some emphasis on the latter because weak
gravitational lensing is entering a new phase in which systematics are becoming
the major source of uncertainty. Accurate simulations are necessary to perform
a reliable calibration of the ellipticity measurements on which the final bias
depends.
  As a test case, we process $7038$ galaxies observed with the ACS/WFC stacked
images of the Hubble eXtreme Deep Field (XDF) and measure the accuracy of the
reconstructions in terms of their moments of brightness, which turn out to be
comparable to what can be achieved with well-established weak-lensing
algorithms.
