cv2.remap()简要介绍

定义

cv2.remap(img,map1,map2,interpolation)

用法

cv2.remap(img,map1,map2,interpolation)
函数作用重映射,即把一幅图像内的像素点放置到另外一幅图像内的指定位置
img输入图像
map1

1.表示(x,y)的一个映射

2.或者表示CV_16SC2 , CV_32FC1, CV_32FC2 类型(x,y)点的 x 值

map2

1.若map1表示(x,y),该值为空

2.若map1表示(x,y)的x值,该值为CV_16SC2 , CV_32FC1类型(x,y)的y值

示例

可以看到,输出的图像像素值均来自于第4列第2行,即坐标(x,y)为(4,2)

import numpy as np 
import cv2
    
a = np.random.randint(0,256,(10,10),dtype='uint8')
mapx = np.ones(a.shape,dtype=np.float32)*4
mapy = np.ones(a.shape,dtype=np.float32)*2
b = cv2.remap(a,mapx,mapy,interpolation=cv2.INTER_LINEAR)

print(a)
print(mapx)
print(mapy)
print(b)

>>>[[211   3 213 228 171  11 146  27  87  94]
    [177 254  86 169  42 191 103  58 220 193]
    [105 246 236 141 226 171  55 138 198 253]
    [ 93 163  74 119 133 170 192  10  54 189]
    [ 44 171 252 139 117 152 115 216 131 118]
    [  7 166 170 211 182   7 214  84  26  33]
    [159  84 205 111  48  34  41  26 215  91]
    [109  85 193 187  72 169 251   4 130 105]
    [ 94 139  88 177 162  14  61 220  55 254]
    [234 243 201 211  42 104 226 119 132  51]]

[[4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]
 [4. 4. 4. 4. 4. 4. 4. 4. 4. 4.]]

[[2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
 [2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]]

[[226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]
 [226 226 226 226 226 226 226 226 226 226]]

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值