Compute object's foreground mask in screen coordinates
I was not aware of Blender's ability to render the scene depth map. This is exactly what I need to obtain the foreground mask. The code snippet at the link below produces the desired results, specifically when setting the map.size value to a very low number, e.g. 0.001.

Render depth map to image with python script