I am creating a synthetic hand dataset for machine learning. I am rendering images of characters with different hand gestures in Blender. At the same time, I want to generate a hand mask for each rendered image to indicate the position of the hand in the RGB image. For example, the hand mask would be an image in which every pixel that is part of the hand at corresponding position in the rendered RGB image has value 1, all other pixels have value 0.
How do I generate the hand mask? My intuition tells me that I need to select all vertices belonging to the hand, then calculate the projection of these pixels onto the image plane. However, I am new to Blender so do not know how to do this or if this is possible.