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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started