OpenCV python image washout

Viewed 1189

I am trying to get average merged image to show up using the following code:

import numpy as np
import cv2
import matplotlib.pyplot as plt

dolphin=cv2.imread('dolphin.png',0) #Also tried without the 0
bicycle=cv2.imread('bicycle.png',0)

Bycycle - original Dolphin - original

The following code adds the two images and result is same as whats shown in the course. But a simple addition avg=img1+img2 doesnt work.

Simple addition - washout areas

sumimg=cv2.add(dolphin,bicycle)
cv2.imshow('Sum image', sumimg)

Two images added together without any modification - washout areas are due to addition being over 255 for that element so the value is set to 255

cv2.waitKey(0)
cv2.destroyAllWindows()

Following code just gives me a white image. When I try to display an half intensity dolphin or cycle ...same result except for a few black dots

Adding images with division by 2

avgimg=cv2.add(dolphin/2,bicycle/2)

same result obtained by avgimg=img1/2+img2/2

cv2.imshow('Avg image', avgimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

The Udacity course shows that if you add images by division by 2 you should get this: From Udacity course - two images added after dividing by 2

So the question is: When I divide either of the image by 2, the matrix contains values below 255 and addition of two matrices also contains values below 255, why then is the resulting image a complete washout?

1 Answers
Related