# Blender RGB masking with segmentation. How to? If possible

I have a 3d small garden with 15 plants. Each plant have leaf objects. Formally they are just a leaf objects with different XYZ location/rotation/scale. Take a look

I want to get something similar to this image:

I need to make an RGB mask of my garden? How do I make it?

I'm thinking of creating a new materials and give them random coloring and then apply materials on my leaf objects, that would work too I suppose, but I believe there should be an easier and better way.

Here's my script:

for obj in [o for o in source_collection.objects if o.type == 'MESH']:
for i in range(1):
for obj in [o for o in source_collection.objects if o.type == 'MESH']:
# get a copy of the object
new_obj = duplicate( obj, destination_collection, False )
# ** Make your random transforms here **
bpy.data.materials["RGBMask"].diffuse_color = random(), random(), random(), random()
rotateX = round(uniform(-20,20), 2)
rotateY = round(uniform(10,50), 2)
rotateZ = randint(-760,760)
scaleX = round(uniform(0.3,1), 2)
scaleY = round(uniform(0.3,1), 2)
scaleZ = round(uniform(0.3,1), 2)
new_obj.scale = ( scaleX, scaleY, scaleZ )


It creates new material called RGBMask, but applies it for all of my objects, but I need to have each leaf have it's own color. I'm new to python and blender, so any help is highly appreciated

• I believe cryptomatte is what you want: youtube.com/watch?v=Ml1Kic4VopA Aug 9 '19 at 12:03
• @rjg it's very close to what I want, figuring out now how to use it. Thanks for the tip!!!!
– cxnt
Aug 9 '19 at 12:42
• You can use the vision_blender add-on for this. It crates segmentations masks for you when you render an image. Sep 29 '20 at 7:58

You can try with this solution: Create a segmentation picture with each object class rendered in different color ?. It worked for me.

Moreover, if you want sharp edges you can set render properties -> film -> filter size for eevee to 0.00.