Calculation Of Resulting 2D Image After Lens This is a tough question!
I would like to calculate how an image (a real 2D photograph) looks if I place a lens at a certain distance d1 from it and I observe it at a certain distance $d_2$.
It is frustrating. All textbook always only treat 1D Images. 
Geometric distorsion: 


*

*Image (2D photograph)





*I place a lens at a certain distance d1 above my image and look at the lens  at a certain distance $d_2$. This is what I would get:



I have looked into Ray transfer matrix analysis, but I could't figure out how to compute such a distorsion of the image, which is also coherent with physics. 
Image blurr
Another effect of a lens, is that things can appear in focus or out of focus depending on the focal distance $f$ and your position $d_2$.


*

*Image in focus $d2=f$





*Image out of focus $d2 < f$ or $d2 > f$



In the end I would like to write a neat mathematica code, in which you can import an image and based on the parameters, $d1$, $f$ and $d2$ it will create the resulting image, including distorsion and blurr in a physical meaningfull way.
But first I need to understand the physics correctly. :)
I would highly appreciate any help! :)
 A: First, one needs to understand that there may be additional lenses, such as the one in your eye or in the camera that help to produce the image that your see. If we ignore such a lens and consider only one lens then one can compute the result as follows. (One can include the additional lenses, but then computation would need a few extra steps.)
Let's assume there is an object at $z=0$, scattering light toward an observer (in the $z$-direction). Between the object and the observer ther is a lens located at $z=L_1$ and the observer is located at $z=L_2>L_1$.
The light shown in your images is poly-chromatic (consist of multiple colours). So you'll need to perform the calculation for all the different colours and then add the results.
The first step is the perform the free space propagation of the light coming from the object. The general expression takes the form
$$ g(u,v) = \int f(x,y) K_z(u-x,v-y) dx dy . $$
Here $f(x,y)$ is the two-dimensional function of the light field coming from the object, in the plane of the object; $g(u,v)$ is the light field at a location $z$; and $K_z(u-x,v-y)$ is the appropriate kernel function for propagation of the light over a distance $z$. The nature of the kernel function depends on the nature of the light, namely, whether it is coherent, or incoherent. In case the light is coherent, the kernel is given by the Fresnel kernel
$$ K_z(u-x,v-y) = \Phi(u-x,v-y) , $$
where
$$ \Phi(x,y) = \frac{i}{\lambda z} \exp\left[\frac{-i\pi}{\lambda z}(x^2+y^2)\right] . $$
(Here, I've used the convention that phase increases with time.) The kernel function in the case of incoherent imagining is a bit more complicated. In general one needs to consider the propagation of the mutual coherence function of the optical field, which is the correlation function of the optical field with itself, each of which is propagated as if it is a coherent field. See for instance the van Cittert-Zernike theorem.
So the idea is now to propagate the light all the way to the lens. Then one multiplies the light field with the transmission function of the lens, which is given by
$$ t(x,y) = \exp\left[\frac{i\pi}{\lambda f}(x^2+y^2)\right] , $$
where $f$ is the focal length of the lens.
The result after the lens is then propagated again over the distance between the lens and the observer. Again, the situation is a bit more involved with incoherent light. I suggest you read up on optical transfer functions for a general treatment.
You'll notice that the expressions depend on the wavelength $\lambda$. So if the image contains multiple colours one needs to perform this computation for all the different wavelengths (colours) and then add (or integrate over) the results in the end.
Hope this addresses your needs.
