“多项式次数越高,能拟合的情况就越多”的理解

一个二次方程最多两个解   而一个100次方程  最多100个解  也就是它能穿过100个点

转载于:https://www.cnblogs.com/bingws/p/10134469.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于这个问题,我们可以使用RANSAC算法来实现。RANSAC算法可以通过随机选取一部分特征点来进行多项式拟合,并计算出拟合误差。然后,根据拟合误差和阈值,筛选出符合条件的内部特征点和外部特征点,分别用于计算内符合精度和外符合精度。 以下是使用RANSAC算法计算内符合精度和外符合精度的Python代码: ```python import cv2 import numpy as np from matplotlib import pyplot as plt # 读取Quickbird参考影像和高景影像 ref_img = cv2.imread('ref_image.tif', 0) tgt_img = cv2.imread('tgt_image.tif', 0) # 提取Quickbird影像和高景影像的特征点 sift = cv2.xfeatures2d.SIFT_create() ref_kp, ref_des = sift.detectAndCompute(ref_img, None) tgt_kp, tgt_des = sift.detectAndCompute(tgt_img, None) # 匹配Quickbird影像和高景影像的特征点 bf = cv2.BFMatcher() matches = bf.knnMatch(ref_des, tgt_des, k=2) # 挑选好的匹配点 good_matches = [] for m, n in matches: if m.distance < 0.75 * n.distance: good_matches.append(m) # 获取匹配点的坐标 ref_pts = np.float32([ref_kp[m.queryIdx].pt for m in good_matches]).reshape(-1, 1, 2) tgt_pts = np.float32([tgt_kp[m.trainIdx].pt for m in good_matches]).reshape(-1, 1, 2) # 使用RANSAC算法进行多项式拟合 M, mask = cv2.findHomography(tgt_pts, ref_pts, cv2.RANSAC, 5.0) # 计算内符合精度 inliers = mask.ravel().tolist() inlier_pts = np.float32([tgt_pts[i] for i in range(len(inliers)) if inliers[i]]) inlier_ref_pts = np.float32([ref_pts[i] for i in range(len(inliers)) if inliers[i]]) mse_in = np.mean((inlier_ref_pts - cv2.perspectiveTransform(inlier_pts, M)) ** 2) rmse_in = np.sqrt(mse_in) print('RMSE (inliers):', rmse_in) # 计算外符合精度 outliers = [not i for i in inliers] outlier_pts = np.float32([tgt_pts[i] for i in range(len(outliers)) if outliers[i]]) outlier_ref_pts = np.float32([ref_pts[i] for i in range(len(outliers)) if outliers[i]]) mse_out = np.mean((outlier_ref_pts - cv2.perspectiveTransform(outlier_pts, M)) ** 2) rmse_out = np.sqrt(mse_out) print('RMSE (outliers):', rmse_out) # 显示配准后的影像 aligned_img = cv2.warpPerspective(tgt_img, M, (ref_img.shape[1], ref_img.shape[0])) plt.subplot(1, 2, 1) plt.imshow(ref_img, cmap='gray') plt.title('Reference Image') plt.subplot(1, 2, 2) plt.imshow(aligned_img, cmap='gray') plt.title('Aligned Image') plt.show() ``` 在代码中,我们使用cv2.findHomography函数进行多项式拟合,并传入cv2.RANSAC作为参数,启用RANSAC算法。函数返回一个变换矩阵和一个掩膜,掩膜标记了哪些特征点被用于拟合,哪些特征点被认为是外部点。我们根据掩膜筛选出内部特征点和外部特征点,并计算内符合精度和外符合精度。最后,代码显示了配准前后的影像。 需要注意的是,在使用RANSAC算法时,需要选择合适的阈值。阈值小,选择的内部特征点少,精度越高,但可能会漏选一些内部点;阈值大,选择的内部特征点多,精度低,但可能会将一些外部点误判为内部点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值