programmatically creating a height map

I want to use color data from a world height map to programmaticaly make a height map on unity terrain. Is this doable? if yes, how?

Translate the color data to a 2D array of floats, where 0 = lowest point and 1 = highest point, and use that in TerrainData.SetHeights(). See also HeightmapFromTexture.