详细代码请见github
def mix_imgs(im_1, im_2, proportion):
"""
图像融合(叠加)
:param im_1:图像1
:param im_2: 图像2
:param proportion:融合度
:return: 融合后图像
"""
# 获取图像大小
im_1_x, im_1_y,im_1_z = im_1.shape
im_2_x, im_2_y,im_2_z = im_2.shape
# 比较图像大小,找出最大尺寸
if im_1_x > im_2_x:
max_x = im_1_x
else:
max_x = im_2_x
if im_1_y > im_2_y:
max_y = im_1_y
else:
max_y = im_2_y
# 创建两个符合最大尺寸的矩阵
im_1_filled_with_0 = np.zeros((max_x,max_y,3))
im_2_filled_with_0 = np.zeros((max_x,max_y,3))
# 在矩阵中添加图片
im_1_filled_with_0[0:im_1.shape[0], 0:im_1.shape[1], :] = im_1
im_2_filled_with_0[0:im_2.shape[0], 0:im_2.shape[1], :] = im_2
# 根据融合度相加
mix_im = proportion * im_1_filled_with_0 + (1 - proportion) * im_2_filled_with_0
mix_im = mix_im.astype(np.uint8)
return mix_im
def sub_imgs(im_1,im_2,type="front"):
"""
图像相减
:param im_1: 图像1
:param im_2: 图像2
:param type: 相减顺序 front: im_1-im_2 back:im_2-im_1
:return:
"""
im_1 = im_1.astype(np.int16)
im_2 = im_2.astype(np.int16)
if type=='front':
subed_img = np.abs(im_1 - im_2)
elif type=='back':
subed_img = np.abs(im_2 - im_1)
subed_img = subed_img.astype(np.uint8)
return subed_img
一二已实现
class ThreadDynamic(QThread):
# 定义一个信号
signal_change = pyqtSignal(str)
def __init__(self):
super().__init__()
self.img = None
self.gauss_img = None
self.sess = True
def run(self):
rotate = 0 # 旋转角度
im = Image.fromarray(self.img)
w, h = im.size
while self.sess:
rotate += 10 # 旋转角度逐渐相加
self.gauss_img = np.array(im.rotate(rotate)) # 执行旋转操作
time.sleep(0.1)
self.signal_change.emit(" ") # 发送信号
添加两张图像, 长宽分别长
选择融合,点击运行
改变下方拉条可实现不同程度融合
2.
选择相减,再分别选择A-B与B-A后点击执行
3.
效果如1,2所示
4.
进行旋转