code: def center_nonzero(self):
          
          # get the center of the nonzero pixels
          nonzero_px = np.where(self._data != 0.0)
          nonzero_px = np.c_[nonzero_px[0], nonzero_px[1]]
          mean_px = np.mean(nonzero_px, axis=0)
          center_px = (np.array(self.shape) / 2.0)[:2]
          diff_px = center_px - mean_px
  
          # transform image
          nonzero_px_tf = nonzero_px + diff_px
          nonzero_px_tf[:, 0] = np.max(
              np.c_[np.zeros(nonzero_px_tf[:, 0].shape), nonzero_px_tf[:, 0]], axis=1)
          nonzero_px_tf[:, 0] = np.min(np.c_[(
              self.height - 1) * np.ones(nonzero_px_tf[:, 0].shape), nonzero_px_tf[:, 0]], axis=1)
          nonzero_px_tf[:, 1] = np.max(
              np.c_[np.zeros(nonzero_px_tf[:, 1].shape), nonzero_px_tf[:, 1]], axis=1)
          nonzero_px_tf[:, 1] = np.min(np.c_[(
              self.width - 1) * np.ones(nonzero_px_tf[:, 1].shape), nonzero_px_tf[:, 1]], axis=1)
          nonzero_px = nonzero_px.astype(np.uint16)
          nonzero_px_tf = nonzero_px_tf.astype(np.uint16)
          shifted_data = np.zeros(self.shape)
          shifted_data[nonzero_px_tf[:, 0], nonzero_px_tf[:, 1],
                       :] = self.data[nonzero_px[:, 0], nonzero_px[:, 1]].reshape(-1, self.channels)
  
          return type(self)(
              shifted_data.astype(
                  self.data.dtype), frame=self._frame), diff_px
docs: Recenters the image on the mean of the coordinates of nonzero pixels.
  
          Returns
          -------
          :obj:`Image`
              A new Image of the same type and size that is re-centered
              at the mean location of the non-zero pixels.