Question: Add random uniform noise (np.random.rand) to an image (random values from 0 - 50) then rescale the image (0-255). Use Gaussian blurring (i.e. low pass

Add random uniform noise (np.random.rand) to an image (random values from 0 - 50) then rescale the image (0-255). Use Gaussian blurring (i.e. low pass filter) with 4 different sigma values (sigma=0.5, 0.2, 1, 5 ) to reduce the effect of noise in the image (scipy.ndimage.gaussian_filter). NOTE: only blur within channels, not across channels (e.g. sigma=[1,1,0]). Plot the original image alongside the noisy and the four final (blurred) images (6 images total). Please show in python

This is what I have so far although not correct:

from scipy.ndimage import gaussian_filter import numpy as np import cv2 img = cv2.imread(img_path) mean = 0 var = 10 sigma = var ** 0.5 sigma1 = var ** 0.2 sigma2 = var ** 1 sigma3 = var ** 5

gaussian = np.random.normal(mean, sigma) gaussian1 = np.random.normal(mean, sigma1) gaussian2 = np.random.normal(mean, sigma2) gaussian3 = np.random.normal(mean, sigma3)

noisy_image = np.zeros(img.shape, np.float32)

if len(img.shape) == 2: noisy_image = img + gaussian else: noisy_image[:, :, 0] = img[:, :, 0] + gaussian noisy_image[:, :, 1] = img[:, :, 1] + gaussian2 noisy_image[:, :, 2] = img[:, :, 2] + gaussian3

cv2.normalize(noisy_image, noisy_image, 0, 255, cv2.NORM_MINMAX, dtype=-1) noisy_image = noisy_image.astype(np.uint8)

result = gaussian_filter(guassian, sigma=sigma) cv2.imshow("img", img) cv2.imshow("gaussian(.5)", result) cv2.imshow("noisy(.2)", noisy_image)

cv2.waitKey(0)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!