As everyone suggested already, the weird colors you're observing are overflow. And as you point out in the comment of schnaader's answer you still get overflow if you add your images like this:

``````addition=(im1arr+im2arr)/2
``````

The reason for this overflow is that your NumPy arrays (im1arr im2arr) are of the uint8 type (i.e. 8-bit). This means each element of the array can only hold values up to 255, so when your sum exceeds 255, it loops back around 0:

``````>>>array([255,10,100],dtype='uint8') +  array([1,10,160],dtype='uint8')
array([ 0, 20,  4], dtype=uint8)
``````

To avoid overflow, your arrays should be able to contain values beyond 255. You need to convert them to floats for instance, perform the blending operation and convert the result back to uint8:

``````im1arrF = im1arr.astype('float')
im2arrF = im2arr.astype('float')
``````

You should not do this:

``````addition = im1arr/2 + im2arr/2
``````

as you lose information, by squashing the dynamic of the image (you effectively make the images 7-bit) before you perform the blending information.

MATLAB note: the reason you don't see this problem in MATLAB, is probably because MATLAB takes care of the overflow implicitly in one of its functions.

### Python版在图片上添加图片_talk_8的专栏-CSDN博客_python 插入图片

https://blog.csdn.net/talk_8/article/details/82262600

2018年8月31日 ... 在介绍完给图上添加文字后，我们再介绍给图片上添加图片，也就是图片的叠加。 需要使用的Python的图像库：PIL.更加详细的知识点 ...

### NumPy, PIL adding an image - Stack Overflow

Blend does not require that the images have alpha layers. Try this: from PIL import Image im1 = Image.open('/Users/rem7/Desktop ...

### python利用pillow包处理图片- 知乎

https://zhuanlan.zhihu.com/p/94343454

2019年11月29日 ... import requests from PIL import Image, ImageDraw, ImageFont ... 这里插入一个题 外话，可能大家是通过爬虫把图片链接拿到了，但是不知道怎么 ...

### Python 技术篇-用PIL库实现图片剪切、粘贴实例演示_小蓝枣的博客 ...

https://blog.csdn.net/qq_38161040/article/details/93404163

2019年6月23日 ... Python 技术篇-用PIL库实现图片剪切、粘贴实例演示。首先需要安装PIL 库，直接 pip install pillow就好了。图片粘贴功能 ... 在这里插入图片描述 ...

### Image Module — Pillow (PIL Fork) 8.2.0 documentation

If you have an image in NumPy: from PIL import Image import numpy as np im = Image.open('hopper.jpg') a = np.asarray(im). Then this can be used to convert it ...

### python 读取并显示图片的两种方法- 邊城浪子- 博客园

https://www.cnblogs.com/yinxiangnan-charles/p/5928689.html

2016年10月3日 ... 在python 中除了用opencv，也可以用matplotlib 和PIL 这两个库操作图片 ... 显示 图片. 复制代码. import matplotlib.pyplot as plt # plt 用于显示图片 ...

### PIL（pillow）简单使用：新建画布、添加文字、画矩形、裁剪、粘贴_ ...

https://blog.csdn.net/mouday/article/details/104377027

2020年2月18日 ... 图片： 在这里插入图片描述. 2、画布上加一些文字 # -*- coding: utf-8 -*- from PIL import Image, ImageDraw, ImageFont # 参数：模式、大小、 ...

### tkinter插入图片- CSDN

https://www.csdn.net/tags/MtTacg0sMTE3NDQtYmxvZwO0O0OO0O0O.html

from PIL import Image,ImageTk import tkinter as tk# 简单插入显示def show_jpg(): root = tk.Tk() im=Image.open("test.jpg") img=ImageTk.PhotoImage(im) ...

### How do you composite an image onto another image with PIL in ...

https://stackoverflow.com/questions/2563822/how-do-you-composite-an-image-onto-another-image-with-pil-in-python

This can be accomplished with an Image instance's paste method: from PIL import Image img = Image.open('/path/to/file', 'r') img_w, img_h ...

### Python PIL | Image.open() method - GeeksforGeeks

https://www.geeksforgeeks.org/python-pil-image-open-method/

Jul 17, 2019 ... Imports PIL module. from PIL import Image. # open method used to open different extension image file. im = Image. open (r ...

### Why can't Python import Image from PIL? - Stack Overflow

https://stackoverflow.com/questions/26505958/why-cant-python-import-image-from-pil

I had the same error. Here was my workflow. I first installed PIL (not Pillow) using pip install --no-index -f https://dist.plone.org/thirdparty/ -U PIL.

### Working with Images in Python - GeeksforGeeks

https://www.geeksforgeeks.org/working-images-python/

May 30, 2018 ... To import the Image module, our code should begin with the following line: from PIL import Image. Operations with Images: Open a particular ...

### How To Add Images In Tkinter - Using The Python Pillow Package

To display an image requires the use of Image and ImageTk imported from the Python Pillow (aka PIL) package. A label widget can display either PhotoImage or ...

### Basics For Displaying Image In Tkinter Python

https://www.c-sharpcorner.com/blogs/basics-for-displaying-image-in-tkinter-python

Mar 17, 2020 ... Introduction · from tkinter import * · from PIL import ImageTk,Image · root = Tk() · canvas = Canvas(root, width = 300, height = 300) · canvas.pack() ...

### Images | Python | Plotly

https://plotly.com/python/images/

Image can be the URL of an image, or a PIL Image object ( from PIL import Image ; img = Image.open('filename.png') ) ...