图像融合
在图像处理中,可以将两张图片可以通过cv2.addWeighted( )按权重进行融合。
注:两张图片必须是相同shape才行,所以很多时候就涉及到用cv2.resize( ) 进行对图片大小的处理。
这里咱们先resize一下吧!
cv2.resize( )函数说明
其中:
scr:原图
dsize:输出图像尺寸【注意:在一般表示中,我们用 高 × 宽 × 通道。使用cv2.resize()时,参数输入是 宽 × 高 × 通道 ,与以往操作不同,需要注意。】
fx:沿水平轴的比例因子
fy:沿垂直轴的比例因子
interpolation:插值方法
interpolation
插值方法
INTER_NEAREST
最近邻插值
INTER_LINEAR
双线性插值(默认设置)
INTER_AREA
使用像素区域关系进行重采样。 它可能是图像抽取的首选方法,因为它会产生无云纹理的结果。 但是当图像缩放时,它类似于INTER_NEAREST方法。
INTER_CUBIC
4x4像素邻域的双三次插值
INTER_LANCZOS4
8x8像素邻域的Lanczos插值
先看看咱们的背景图片规格:
咱们把它转化为600x600分辨率的图片
再来看看笔者王者巅峰赛的图片:
也把它转化为600x600分辨率的图片,和上面同样的代码,不再赘述。
cv2.addWeighted( )函数说明
dst = src1 * alpha + src2 * beta + gamma
其中:
src1 – first input array. 【第一张图片】
alpha – weight of the first array elements. 【第一张图片的权重】
src2 – second input array of the same size and channel number as src1. 【与第一张大小和通道数相同的图片】
beta – weight of the second array elements. 【第二张图片的权重】
dst – output array that has the same size and number of channels as the input arrays.【输出,python中可以直接将dst放在前面作为输出】
gamma – scalar added to each sum.【加到每个总和上的标量,相当于调亮度】
dtype – optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().
融合前的两张图
融合后的效果,多了一丝朦胧感哈,融合权重5:5
代码如下:
在图像处理中,可以将两张图片可以通过cv2.addWeighted( )按权重进行融合。
注:两张图片必须是相同shape才行,所以很多时候就涉及到用cv2.resize( ) 进行对图片大小的处理。
这里咱们先resize一下吧!
cv2.resize( )函数说明
其中:
scr:原图
dsize:输出图像尺寸【注意:在一般表示中,我们用 高 × 宽 × 通道。使用cv2.resize()时,参数输入是 宽 × 高 × 通道 ,与以往操作不同,需要注意。】
fx:沿水平轴的比例因子
fy:沿垂直轴的比例因子
interpolation:插值方法
interpolation
插值方法
INTER_NEAREST
最近邻插值
INTER_LINEAR
双线性插值(默认设置)
INTER_AREA
使用像素区域关系进行重采样。 它可能是图像抽取的首选方法,因为它会产生无云纹理的结果。 但是当图像缩放时,它类似于INTER_NEAREST方法。
INTER_CUBIC
4x4像素邻域的双三次插值
INTER_LANCZOS4
8x8像素邻域的Lanczos插值
先看看咱们的背景图片规格:
咱们把它转化为600x600分辨率的图片
再来看看笔者王者巅峰赛的图片:
也把它转化为600x600分辨率的图片,和上面同样的代码,不再赘述。
cv2.addWeighted( )函数说明
dst = src1 * alpha + src2 * beta + gamma
其中:
src1 – first input array. 【第一张图片】
alpha – weight of the first array elements. 【第一张图片的权重】
src2 – second input array of the same size and channel number as src1. 【与第一张大小和通道数相同的图片】
beta – weight of the second array elements. 【第二张图片的权重】
dst – output array that has the same size and number of channels as the input arrays.【输出,python中可以直接将dst放在前面作为输出】
gamma – scalar added to each sum.【加到每个总和上的标量,相当于调亮度】
dtype – optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().
融合前的两张图
融合后的效果,多了一丝朦胧感哈,融合权重5:5
代码如下: