def plot_errors(self): """ Display plots of error distributions""" import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 1, tight_layout=True) errors, valid = tables.reprojection_error(self.reprojected, self.point_table) errors, valid = errors.ravel(), valid.ravel() inliers = self.inliers.ravel() outliers = (valid & ~inliers).ravel() axs[0].scatter(x=np.arange(errors.size)[inliers], y=errors[inliers], marker=".", label='inlier') axs[0].scatter(x=np.arange(errors.size)[outliers], y=errors[outliers], color='r', marker=".", label='outlier') axs[1].hist(errors[valid], bins=50, range=(0, np.quantile(errors[valid], 0.999))) plt.show()
def reprojection_tables(calib, inlier_only=False): point_table = calib.point_table if inlier_only: point_table = point_table._extend(valid=calib.inliers) error, valid = tables.reprojection_error(calib.projected, point_table) def f(axis): return reprojection_statistics(error, valid, calib.inliers, axis=axis) return sum_axes._map(f)
def reject_outliers(self, threshold): """ Set outlier threshold """ errors, valid = tables.reprojection_error(self.reprojected, self.point_table) inliers = (errors < threshold) & valid num_outliers = valid.sum() - inliers.sum() inlier_percent = 100.0 * inliers.sum() / valid.sum() info(f"Rejecting {num_outliers} outliers with error > {threshold:.2f} pixels, " f"keeping {inliers.sum()} / {valid.sum()} inliers, ({inlier_percent:.2f}%)") return self.copy(inlier_mask = inliers)