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')
additionF = (im1arrF+im2arrF)/2
addition = additionF.astype('uint8')
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.
2018年8月31日 ... 在介绍完给图上添加文字后,我们再介绍给图片上添加图片,也就是图片的叠加。 需要使用的Python的图像库:PIL.更加详细的知识点 ...
Blend does not require that the images have alpha layers. Try this: from PIL import Image im1 = Image.open('/Users/rem7/Desktop ...
2019年11月29日 ... import requests from PIL import Image, ImageDraw, ImageFont ... 这里插入一个题 外话,可能大家是通过爬虫把图片链接拿到了,但是不知道怎么 ...
2019年6月23日 ... Python 技术篇-用PIL库实现图片剪切、粘贴实例演示。首先需要安装PIL 库,直接 pip install pillow就好了。图片粘贴功能 ... 在这里插入图片描述 ...
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 ...
2016年10月3日 ... 在python 中除了用opencv,也可以用matplotlib 和PIL 这两个库操作图片 ... 显示 图片. 复制代码. import matplotlib.pyplot as plt # plt 用于显示图片 ...
2020年2月18日 ... 图片: 在这里插入图片描述. 2、画布上加一些文字 # -*- coding: utf-8 -*- from PIL import Image, ImageDraw, ImageFont # 参数:模式、大小、 ...
from PIL import Image,ImageTk import tkinter as tk# 简单插入显示def show_jpg(): root = tk.Tk() im=Image.open("test.jpg") img=ImageTk.PhotoImage(im) ...
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 ...
Jul 17, 2019 ... Imports PIL module. from PIL import Image. # open method used to open different extension image file. im = Image. open (r ...
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.
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 ...
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 ...
Mar 17, 2020 ... Introduction · from tkinter import * · from PIL import ImageTk,Image · root = Tk() · canvas = Canvas(root, width = 300, height = 300) · canvas.pack() ...
Image can be the URL of an image, or a PIL Image object ( from PIL import Image ; img = Image.open('filename.png') ) ...
Mar 22, 2019 ... load and show an image with Pillow. from PIL import Image. # load the image. image = Image.open('opera_house.jpg'). # summarize some ...