python分片实现矩阵下采样,在python中对2d numpy数组进行下采样

I'm self learning python and have found a problem which requires down sampling a feature vector. I need some help understanding how down-sampling a array. in the array each row represents an image by being number from 0 to 255. I was wonder how you apply down-sampling to the array? I don't want to scikit-learn because I want to understand how to apply down-sampling.

If you could explain down-sampling too that would be amazing thanks.

the feature vector is 400x250

解决方案

If with downsampling you mean something like this, you can simply slice the array. For a 1D example:

import numpy as np

a = np.arange(1,11,1)

print(a)

print(a[::3])

The last line is equivalent to:

print(a[0:a.size:3])

with the slicing notation as start:stop:step

Result:

[ 1 2 3 4 5 6 7 8 9 10]

[ 1 4 7 10]

For a 2D array the idea is the same:

b = np.arange(0,100)

c = b.reshape([10,10])

print(c[::3,::3])

This gives you, in both dimensions, every third item from the original array.

Or, if you only want to down sample a single dimension:

d = np.zeros((400,250))

print(d.shape)

e = d[::10,:]

print(e.shape)

(400, 250)

(40, 250)

The are lots of other examples in the Numpy manual

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现高景影像的相对配准可以分为以下几个步骤: 1. 读取Quickbird影像和高景影像,将它们转换为numpy数组。 2. 提取Quickbird影像的特征点和高景影像的特征点,可以使用SIFT、SURF、ORB等算法进行特征点提取。 3. 对提取到的特征点进行匹配,可以使用FLANN或者暴力匹配等算法进行特征点匹配。 4. 使用二次多项式函数拟合匹配点对,得到配准变换矩阵。 5. 对高景影像进行变换,使其与Quickbird影像对齐。 6. 对配准结果进行评价,可以使用误差向量或者均方根误差等指标进行评价。 下面是一个简单的Python代码示例,用于实现高景影像的相对配准和配准精度评价: ```python import cv2 import numpy as np # 读取Quickbird影像和高景影像 qb_img = cv2.imread('qb_image.tif') hg_img = cv2.imread('hg_image.tif') # 提取Quickbird影像和高景影像的特征点 sift = cv2.xfeatures2d.SIFT_create() qb_kp, qb_des = sift.detectAndCompute(qb_img, None) hg_kp, hg_des = sift.detectAndCompute(hg_img, None) # 对特征点进行匹配 bf = cv2.BFMatcher() matches = bf.knnMatch(qb_des, hg_des, k=2) # 筛选出好的匹配点对 good_matches = [] for m, n in matches: if m.distance < 0.75 * n.distance: good_matches.append(m) # 提取好的匹配点对的坐标 src_pts = np.float32([qb_kp[m.queryIdx].pt for m in good_matches]).reshape(-1, 1, 2) dst_pts = np.float32([hg_kp[m.trainIdx].pt for m in good_matches]).reshape(-1, 1, 2) # 使用二次多项式函数拟合匹配点对 M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) # 对高景影像进行变换 aligned_img = cv2.warpPerspective(hg_img, M, (qb_img.shape[1], qb_img.shape[0])) # 计算配准误差 mse = np.mean((qb_img - aligned_img) ** 2) print('MSE:', mse) ``` 这段代码实现了使用SIFT算法提取Quickbird影像和高景影像的特征点,使用暴力匹配算法进行特征点匹配,使用RANSAC算法拟合匹配点对,使用cv2.warpPerspective函数对高景影像进行变换,使用均方根误差(MSE)评价配准精度。需要注意的是,在实际应用,还需要进行一些预处理操作,如去除影像的边缘、降采样等,以提高配准的精度和效率。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值