Generally and fundamentally, the answer to your question is no. Photography / 2D imaging is the prototypical example of the mathematical notion of projection, which, by its definition, destroys information by extracting "class" information from sets of objects: forgetting about fine differences and reporting only the class. Here, for example, if $z$ is the direction away from the plane of the photograph, a photograph can be roughly described as registering of the $(x, y)$ co-ordinates of each of the objects in the photo, but forgetting about the $z$. Two bright objects at a point $(x,y)$ will yield the same pixel, regardless of their $z$ co-ordinate.
Sometimes you can use further information to extract the $z$. Astronomers must do this all the time through the use of standard candles to infer a the distance to an object of known brightness from its apparent brightness, use of redshift and so forth. See the Cosmic Distance Ladder Wikipedia Page.
Othertimes the photographic method takes specific steps to encode the $z$ information in the 2D representation, and generally one must make an assumption about the kind of object being photographed: commonly that $z$ is a continuous function of $(x,\,y)$, such as when you're looking down from an aircraft onto the land's surface. For example, Structured 3D Light Scanning casts bright, straight fringes onto the object of known spacing and angle, the object's deviation from flatness warps the otherwise straight fringe and the $z$ co-ordinate can be calculated from this essentially triangulation data. Photogrammetry is somewhat similar in principle but very different in technique: it uses stereo photography and makes distance inference by triangulation with the different $(x,y)$ co-ordinates of the same object in two different photographs taken from different points.
Further Comments
User Floris makes the following comment:
Don't forget that focus can provide third dimension. Not very good unless the object is close and the depth of focus shallow (low f number). But then it works...
This is true, but telling whether something is in focus can be harder than you might think. There needs to be fine, known structure in the image for a definitive test, especially if you want the method to be an automated image processing procedure. And the deduction of the z information for everything in the image can only be done with a 3D stack of photos, which are then run through a point spread function deconvolution algorithm (this is the idea of "deconvolution microscopy". The use of coherent light, interferometry and phase reconstruction algorithms is another method to map surfaces with high precision, but this is limited to objects whose $z$ co-ordinate varies by fewer than about 100 wavelengths or so. The phase camera is a method in between straight interferometry and 3D stack deconvolution.