图像数值计算与图像融合

数值计算

img_cat=cv2.imread('cat.jpg')
img_dog=cv2.imread('dog.jpg')
img_cat2= img_cat +10 
img_cat[:5,:,0]

array([[142, 146, 151, …, 156, 155, 154],

​ [107, 112, 117, …, 155, 154, 153],

​ [108, 112, 118, …, 154, 153, 152],

​ [139, 143, 148, …, 156, 155, 154],

​ [153, 158, 163, …, 160, 159, 158]], dtype=uint8)

img_cat2[:5,:,0]

array([[152, 156, 161, …, 166, 165, 164],

​ [117, 122, 127, …, 165, 164, 163],

​ [118, 122, 128, …, 164, 163, 162],

​ [149, 153, 158, …, 166, 165, 164],

​ [163, 168, 173, …, 170, 169, 168]], dtype=uint8)

#相当于% 256
(img_cat + img_cat2)[:5,:,0] 

#相当于% 256

(img_cat + img_cat2)[:5,:,0]

array([[ 38, 46, 56, …, 66, 64, 62],

​ [224, 234, 244, …, 64, 62, 60],

​ [226, 234, 246, …, 62, 60, 58],

​ [ 32, 40, 50, …, 66, 64, 62],

​ [ 60, 70, 80, …, 74, 72, 70]], dtype=uint8)

cv2.add(img_cat,img_cat2)[:5,:,0]

array([[255, 255, 255, …, 255, 255, 255],

​ [224, 234, 244, …, 255, 255, 255],

​ [226, 234, 246, …, 255, 255, 255],

​ [255, 255, 255, …, 255, 255, 255],

​ [255, 255, 255, …, 255, 255, 255]], dtype=uint8)

图像融合

img_cat + img_dog
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-111-ffa3cdc5d6b8> in <module>()
----> 1 img_cat + img_dog

ValueError: operands could not be broadcast together with shapes (414,500,3) (429,499,3) 
img_cat.shape

(414, 500, 3)

img_dog = cv2.resize(img_dog, (500, 414))
img_dog.shape

(414, 500, 3)

res = cv2.addWeighted(img_cat, 0.4, img_dog, 0.6, 0)
plt.imshow(res)

在这里插入图片描述

res = cv2.resize(img, (0, 0), fx=4, fy=4)
plt.imshow(res)

在这里插入图片描述

res = cv2.resize(img, (0, 0), fx=1, fy=3)
plt.imshow(res)

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NDNPOMDFLR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值