Python Blur OpenCV Image

I am trying to get the average merged image to show it with 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 two images, and the result is the same as shown in the course. But just adding avg = img1 + img2 does not work.

Simple additions - erosion zones

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

The two images added together without any changes are the washout areas due to the addition of more than 255 for this element, so the value is set to 255

cv2.waitKey(0)
cv2.destroyAllWindows()

The following code just gives me a white image. When I try to display half the intensity of a dolphin or a cycle ... the same result, except for a few black dots

Adding images divided by 2

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

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

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

The Udacity course shows that if you add images divided by 2, you should get the following: From the Udacity course - two images added after dividing by 2

, : 2, 255, 255, ?

+4
1

( ), , addWeighted(), ( docs):

import numpy as np
import cv2

#load your images
dolphin = cv2.imread('dolphin.png') #use 0 for grayscale
bicycle = cv2.imread('bicycle.png') 
#add them with a weight, respectively, last parameter is a scalar added 
dst = cv2.addWeighted(dolphin,0.7,bicycle,0.3,0) 

#show
cv2.imshow('Blended Image',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

. , , numpy OpenCV , numpy (%), OpenCV ( ), , :

>>> x = np.uint8([250])
>>> y = np.uint8([10])

>>> print( cv2.add(x,y) ) # 250+10 = 260 => 255 , saturated
[[255]]
>>> print( x+y )          # 250+10 = 260 % 256 = 4 , modulo
[4]

, , , add() ( 255 ).

+3

Source: https://habr.com/ru/post/1681228/


All Articles