New to Blender, and the documentation for bpy is throwing me for a few loops. I got a setup in the compositing layer working for my desired goal as shown:


This renders an image and a color-coded mask for each of the three unique pass_index marked objects (below), and am trying to automate this through a bpy script as there are many variations I'll need to render.


Each object can be given a pass index in bpy via e.g. bpy.data.objects['foo'].pass_index = bar, but I'm having trouble figuring out how to separate each layer(?) via pass index as the compositing nodes do. Simple camera manipulations and the like are straightforward (I have a script that can import the stl, setup camera/lighting as required, and produce images like the left one above), but I'm lacking the terminology to search the right question or understand the documentation- and recent changes between 2.7x and 2.8x make a number of older guides very difficult to understand...

Related would be the steps of adding a color and recombining to form a single image as shown in the compositing layer, but small steps first. Any help would be appreciated, thank you!

  • 1
    $\begingroup$ Using ID Masks for compositing is a very bad idea. They will cause serious problems with the edges if used for compositing compared to alternatives. Consider Cryptomatte instead. That's a way better solution in vast majority of cases. $\endgroup$ – Martynas Žiemys Jun 27 '20 at 21:38
  • $\begingroup$ In the days when Cryptomatte was not around, what was the right way and purpose to use ID masks in blender? $\endgroup$ – J. SungHoon Oct 27 '20 at 3:06

Specific answer for the task at hand (image segmentation) is given by the bpycv module. This isn't the same as a general compositor -> bpy solution, but posting here in case someone else also happens to (somehow) miss bpycv, yet find this post.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.