Rectangle coordinates from treemap image

Sure - photo editor would be one option. But I want this in a scripted way. Here I paste some examples. Its always the same structure at the same place but the background changes. So the aim would be to replace the white pixels with the color of the tile it belongs to.