基本原理:两张图片合成。
先按照原来的图片的格式新建一个色素全为零的图片,然后按照两张图的比例不同合成一张新图片。主要用到函数:addWeighted函数
addWeighted()计算两个数组的加权和。函数addWeighted计算两个数组的加权和,如下所示:
其中我是数组元素的多维索引。在多通道阵列的情况下,每个通道都是独立处理的。该函数可以用矩阵表达式替换:
dst = src1*alpha + src2*beta + gamma;
Parameters 参数
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. gamma scalar added to each sum. dst output array that has the same size and number of channels as the input arrays. 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().
1 | def contrast_brightness_demo(image, c, b): |