docs: def detect(self, color_im, depth_im, cfg, camera_intr=None,
                 T_camera_world=None, segmask=None):
          """
          Detects all relevant objects in an rgbd image pair using foreground masking.
  
          Parameters
          ----------
          color_im : :obj:`ColorImage`
              color image for detection
          depth_im : :obj:`DepthImage`
              depth image for detection (corresponds to color image)
          cfg : :obj:`YamlConfig`
              parameters of detection function
          camera_intr : :obj:`CameraIntrinsics`
              intrinsics of the camera
          T_camera_world : :obj:`autolab_core.RigidTransform`
              registration of the camera to world frame
          segmask : :obj:`BinaryImage`
              optional segmask of invalid pixels
  
          Returns
          ------
          :obj:`list` of :obj:`RgbdDetection`
              all detections in the image
          """
          # read params
          foreground_mask_tolerance = cfg['foreground_mask_tolerance']
          min_contour_area = cfg['min_contour_area']
          max_contour_area = cfg['max_contour_area']
          w = cfg['filter_dim']
  
          # mask image using background detection
          bgmodel = color_im.background_model()
          binary_im = color_im.foreground_mask(foreground_mask_tolerance, bgmodel=bgmodel)
  
          # filter the image
          y, x = np.ogrid[-w/2+1:w/2+1, -w/2+1:w/2+1]
          mask = x*x + y*y <= w/2*w/2
          filter_struct = np.zeros([w,w]).astype(np.uint8)
          filter_struct[mask] = 1
          binary_im_filtered = binary_im.apply(snm.grey_closing, structure=filter_struct)
  
          visualize = False
          if visualize:
              plt.figure()
              plt.imshow(binary_im_filtered.data, cmap=plt.cm.gray)
              plt.axis('off')
              plt.show()
  
          # find all contours
          contours = binary_im_filtered.find_contours(min_area=min_contour_area, max_area=max_contour_area)
  
          # convert contours to detections
          detections = []
          for contour in contours:
              box = contour.bounding_box
              color_thumbnail = color_im.crop(box.height, box.width, box.ci, box.cj)
              depth_thumbnail = depth_im.crop(box.height, box.width, box.ci, box.cj)
              binary_thumbnail = binary_im_filtered.crop(box.height, box.width, box.ci, box.cj)
              thumbnail_intr = camera_intr
              if camera_intr is not None:
                  thumbnail_intr = camera_intr.crop(box.height, box.width, box.ci, box.cj)
              detections.append(RgbdDetection(color_thumbnail,
                                              depth_thumbnail,
                                              box,
                                              binary_thumbnail=binary_thumbnail,
                                              contour=contour,
                                              camera_intr=thumbnail_intr))
          return detections