调用python-opencv的多波段融合

调用python-opencv的多波段融合

import cv2
import numpy as np
from get_mask import get_simple_mask   #获取mask

img1 = cv2.imread('a.jpg')
img2 = cv2.imread('b.jpg')
m1,m2 = get_simple_mask(img1, img2)  # 获取的mask最好进行erode  m [0-255]

a = cv2.detail.Blender_createDefault(2)
a.prepare(np.array([0, 0, img1.shape[1], img1.shape[0]]))

a.feed(img1, m1, np.array([0, 0]))   # 多张图片就多次feed
a.feed(img2, m2, np.array([0, 0]))

dst, dst_mask = a.blend(None, None)
dst[dst>255]=255
dst[dst<0]=0
dst = dst.astype(np.uint8) # !!!!!!别忘了,不然就是灰度图

cv2.imshow('i1',img1)
cv2.imshow('i2',img2)
cv2.imshow('out',dst)
cv2.waitKey()


img1 img2

out

ref

  • 【OpenCV】Multiband Blender 用于图像拼缝的平滑
  • opencv 多波段融合

你可能感兴趣的:(opencv,python,图像处理)