Create masks / cryptomatte for every separate object in the scene

Hi, I would like to use blender to generate training data for machine learning algorithm. I’m not experienced in blender but I can write Python scripts.

I want to create masks for every object in the scene and be able to export them as separate masks with encoded object id. I’m only interested in generating masks for visible objects. I know there exists cryptomatte as of blender 2.8 but I haven’t found any automated way to do this for large number of objects. So I’m looking for a script/tool that can make this process automatic.

Below there is a toy example. First is the original image. Second one has separate colors for each object in the array. Each of the object that has this random color should be a separate mask.

Sometimes it is the simple things that help. Unfortunately I don’t know who it was anymore, but I saw it here in the forum. You can just set the workbench render to flat and random and use that for selections in e.g. GIMP.

1 Like

This is an excellent tip! The only problem with this approach would be to get IDs of the objects at each pixel or at least centers. But I think this can be solved by using non-random colors for each object.
For example you can iterate through objects and assign a color and then save the color -> object id mapping in a separate file.

1 Like