Create height bitmap from mesh
If this is for a terrain (I mean the heights are considered from a base plane), you can use a bake to the texture:



This is done using Cycles.

You can see the material nodes settings above:


Input is the location (the location is given from the object's origin, here for simplicity, the object origin is at its baseline)
Only keep the Z value
Divide by the real height of your object (in order to have a resulting value between 0 and 1)
Then put it in a diffuse shader as color
(the texture node have to be present and be the selected node for the bake described below)


To bake:


Go to the render panel and the bake section
Choose diffuse and keep only the "color" option (deselect "direct" and "indirect" as we here want the color only with no environment or other effects)




As indicated in the comments, the previous setting leads to a sharp cutout (visible in the image above: the surrounding is suddenly black).

To avoid that, a possibility is to use another function than just dividing by the object height. What I propose here is to use a sigmoid:


the output is between 0 and 1
the output limits slowly tend to 0 on left and 1 on right


That leads to this kind of result which you can compare to the image above:



In the blend file below, the higher the value for the multiply node is, the more limit rendered values will be sharp.