import re


def find_image_rig(image, rig_patterns):
    """Given an image and candidates rig model patterns, return the
    RigID/RigCameraID/Instance Member ID this image belongs to.
    """
    for rig_id, patterns in rig_patterns.items():
        for rig_camera_id, pattern in patterns.items():
            instance_member_id = re.sub(pattern, "", image)
            if instance_member_id == "":
                continue
            if instance_member_id != image:
                return (rig_id, rig_camera_id, instance_member_id)
    return None, None, None