python - 向灰度图像添加颜色叠加

标签 python opencv

我想在照片上添加预生成的热图。图像中的颜色并不重要,为了突出热图颜色,我将图像设为灰度。我已经使用

    grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

然而,与热图(BRG)相比,灰度图像现在的维度少了一个。如何将热图叠加在灰度图像之上?

最佳答案

在放置了两个相同大小和模式的图像后,执行以下代码。

from PIL import Images

im_1 = Image.open("/constr/pics1/100_canary.png")   

#  mode is RGBA 

im_2 = Image.open("/constr/pics1/100_cockcrow.png")

# Check on mode, size and format first for compatibility. 

# Make both modes the same 

im_4 = Image.blend(im_1, im_2, 0.5) 

im_4.show()

关于python - 向灰度图像添加颜色叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57624849/

相关文章:

Python GUI 编程、许可和理解

python - 包含字母数字和 _ 的正则表达式

python - 使用 Python,查找单词列表的字谜

c++ - 从 cv::Mat 初始化的 IplImage 的内存释放

python - Numpy:如何将颜色矩阵转换为扁平向量

c - 为什么 opencv 中的 FindContours 函数会找到两个轮廓而不是图像中的一个轮廓,如下所示?

Python opencv 没有收到相机提要

python - 使用 Python 将纬度、经度、值 CSV 转换为栅格 map

python - 无法在 pypy3 中导入 numpy(使用 pip 可以正常安装)

c++ - Matlab 仍然比 C++ 中的 opencv 慢吗