docs: def comp_centroid(data, bounding_box, debug_plot=False, plot_reference=None, logger=None):
      """Detect objects in a region and return the centroid of the brightest one"""
  
      from matplotlib.patches import Ellipse
  
      if logger is None:
          logger = logging.getLogger(__name__)
  
      region = bounding_box.slice
      ref_x = region[1].start
      ref_y = region[0].start
      logger.debug('region ofset is %s, %s', ref_x, ref_y)
      subimage = data[region].copy()
      bkg = sep.Background(subimage)
      data_sub = subimage - bkg
      objects = sep.extract(data_sub, 1.5, err=bkg.globalrms)
      # Select brightest object
      logger.debug('%d object found', len(objects))
  
      if len(objects) == 0:
          # print('No objects')
          return None
  
      iadx = objects['flux'].argmax()
      # plot background-subtracted image
      maxflux = objects[iadx]
  
      if debug_plot:
          fig, ax = plt.subplots()
          m, s = np.mean(data_sub), np.std(data_sub)
          ax.imshow(data_sub, interpolation='nearest', cmap='gray',
                    vmin=m - s, vmax=m + s, origin='lower',
                    extent=bounding_box.extent)
          if plot_reference:
              e = Ellipse(xy=(plot_reference[0], plot_reference[1]),
                          width=6,
                          height=6,
                          angle=0)
              e.set_facecolor('none')
              e.set_edgecolor('green')
              ax.add_artist(e)
  
          # plot an ellipse for each object
          for idx, obj in enumerate(objects):
              e = Ellipse(xy=(obj['x'] + ref_x, obj['y'] + ref_y),
                          width=6 * obj['a'],
                          height=6 * obj['b'],
                          angle=obj['theta'] * 180. / np.pi)
              e.set_facecolor('none')
              if idx == iadx:
                  e.set_edgecolor('blue')
              else:
                  e.set_edgecolor('red')
              ax.add_artist(e)
          return maxflux['x'], maxflux['y'], ax
      else:
          return maxflux['x'], maxflux['y']