You are close!
Check this project and the terrain-distribute script on how to read pixel data directly. Most notably these two methods:
TerrainDistribute.prototype.getImageData()
TerrainDistribute.prototype.distribute()
https://playcanvas.com/project/539384/overview/tiled-terrain-manager