I've been working on this for several days, but haven't found any solutions. Please help me out
I want two images per render scene.
- ordinary color rendered image
- only page masked image(Using Material Index pass)
the results is not good and changing every attempt.
any comments would be very helpful.
Thank you
here is my Composite Node.
and below is my python script
def render_and_save(output_path, output_gt_path):
view_layer = bpy.context.view_layer
view_layer.use_pass_material_index = True
bpy.data.images.remove(bpy.data.images.get("Render Result"), do_unlink=True)
bpy.ops.render.render()
render_result = bpy.data.images.get("Render Result")
if render_result is None:
print("Error: 'Render Result' not found.")
return
try:
render_result.render_slots.active_index = 0
render_result.save_render(filepath=output_path)
render_result.render_slots.active_index = 1
render_result.save_render(filepath=output_gt_path)
print(f"Saved image: {output_path}")
except Exception as e:
print(f"Error while saving: {e}")
def main():
.....
for i in range(num_images):
.....
output_color_path = os.path.join(output_dir, f"book_{i:03d}.png")
output_gt_path = os.path.join(output_dir, f"book_GT_{i:03d}.png")
render_and_save(output_color_path, output_gt_path)