code: def foreground_mask(
              self,
              tolerance,
              ignore_black=True,
              use_hsv=False,
              scale=8,
              bgmodel=None):
          
          # get a background model
          if bgmodel is None:
              bgmodel = self.background_model(ignore_black=ignore_black,
                                              use_hsv=use_hsv,
                                              scale=scale)
  
          # get the bounds
          lower_bound = np.array(
              [bgmodel[i] - tolerance for i in range(self.channels)])
          upper_bound = np.array(
              [bgmodel[i] + tolerance for i in range(self.channels)])
          orig_zero_indices = np.where(np.sum(self._data, axis=2) == 0)
  
          # threshold
          binary_data = cv2.inRange(self.data, lower_bound, upper_bound)
          binary_data[:, :, ] = (BINARY_IM_MAX_VAL - binary_data[:, :, ])
          binary_data[orig_zero_indices[0], orig_zero_indices[1], ] = 0.0
          binary_im = BinaryImage(binary_data.astype(np.uint8), frame=self.frame)
          return binary_im
docs: Creates a binary image mask for the foreground of an image against
          a uniformly colored background. The background is assumed to be the mode value of the histogram
          for each of the color channels.
  
          Parameters
          ----------
          tolerance : int
              A +/- level from the detected mean backgroud color. Pixels withing
              this range will be classified as background pixels and masked out.
  
          ignore_black : bool
              If True, the zero pixels will be ignored
              when computing the background model.
  
          use_hsv : bool
              If True, image will be converted to HSV for background model
              generation.
  
          scale : int
              Size of background histogram bins -- there will be BINARY_IM_MAX_VAL/size bins
              in the color histogram for each channel.
  
          bgmodel : :obj:`list` of int
              A list containing the red, green, and blue channel modes of the
              background. If this is None, a background model will be generated
              using the other parameters.
  
          Returns
          -------
          :obj:`BinaryImage`
              A binary image that masks out the background from the current
              ColorImage.