I am trying to add Gaussian noise to my image using opencv-python. I have created the noise function but adding the noise function to the image is producing unexpected results.
I have created a noise function using normal Gaussian distribution from the numpy.random. Then after resizing the noise function I added it to my image.I tried printing the array. There sum is in the interval [0, 255] but then also parts of the image are washed out. I also tried printing the data types of the array. The initial was uint8 while later was float64 (I don't think that will make any difference).
import numpy as np
import cv2
fast = cv2.imread('Fast8.jpg', 0)
row, col = fast.shape
noise = np.random.normal(0, 1, (row, col))
fast = fast + noise
cv2.namedWindow('Noisy', cv2.WINDOW_NORMAL)
cv2.imshow('Noisy', fast)
cv2.waitKey(0)
cv2.destroyAllWindows()
In the result of the above code I am getting a washed out image with only some areas slightly visible.
noisevariable at all.1to0.1?fastis a floating point array.cv2.imshowexpects floating point arrays to have values in the range [0, 1]. Trycv2.imshow('Noisy', fast/fast.max()).np.random.normal(0, 1, (row, col))will include negative values, which meansfast + noisecould have negative values. Is that what you want?