It can be achieved by baking the height of a mesh.
Before you start, make sure that the origin of the object is beneath or at the lowest point of the mesh, preferably the latter. Negative values do not go well with images.
Go to the UV/Image Editor and create a new image
Go to the 3D view, select your mesh, go to edit mode, select all vertices with A, go to orthographic view by pressing numpad 5 and top view by pressing numpad 7.
Press U and click Project From View (Bounds)
Go back to Object Mode, go to the node editor add a new material for the mesh. Add a Texture Coordinate node, a Separate XYZ node and a Math node. Connect the Object output from the Texture Coordinate node to the Vector input of the Separate XYZ node, the Z output of the Separate XYZ node to the upper input of the Math node and the output of the Math node to the Color input of the Diffuse node. Change the operation mode of the Math node to Power and the bottom value to 2.
Add an Image Texture node, select the just created image in it, but do not connect it to any other node.
The Node Editor should look like this:
Make sure you have the Image Texture node selected, go in the Properties Panel to the Render tab. Go to the Bake options, change Bake Type to Diffuse Color and click Bake.
You can now find the height map in the UV/Image Editor by selecting the image you created at the start. Do not forget to save the height map by pressing F3.
Note that this method is not perfect, a mesh created using this height map will not be completely identical to the original mesh.