Using MATLAB write the following function: The Function should be able to: 1) Re
ID: 2248316 • Letter: U
Question
Using MATLAB write the following function:
The Function should be able to:
1) Read in an arbitrary grayscale image given by the file path
2) Calculate the signal to noise ratio of the image using any method from the book
3) Add Gaussian noise to the image for user specified mean and standard deviation
4) Recalculate the signal to noise ratio of the image with noise added
5) Return the image with added noise as well as the noise function that was generated.
6) Return the signal to noise ratio of the image both before and after noise has been added
Explanation / Answer
Following is the working code.
Just give the right path of the image under test in the imagepath line.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all,
clear all,
clc,
ProjectPath = pwd; %Get the Image File Path
ImagePath = strcat(ProjectPath,'Leena.jpg'); %Image File
User_Mean = 0.1; % User defined Mean
User_SD = 0.2; % User defined Standard Deviation
scrsz = get(0,'ScreenSize');
Dim=10;
figure('Position',[scrsz(1)+Dim, scrsz(2)+Dim,scrsz(3)-20,scrsz(4)-100]); % To get the display on largest screen size
Orig = imread(ImagePath); subplot(1,3,1); imshow(Orig); title('Original Image');
Gray = rgb2gray(Orig); subplot(1,3,2); imshow(Gray); title('Gray Image');
Mean = mean(mean(double(Gray))); %Mean of the Original Image
SD = std(std(double(Gray))); % Standard Deviation of the Original Image
SNR_Orig = Mean/SD; % SNR = Mean/Std. Dev.
NoisyImage = imnoise(Gray,'gaussian',User_Mean,User_SD); subplot(1,3,3); imshow(NoisyImage); %Gausian Noise Addition
str = strcat('Noisy Imag with Mean = ',num2str(Mean),' and SD = ',num2str(SD));
title(str);
Mean = mean(mean(double(NoisyImage))); %Mean of the Noisy Image
SD = std(std(double(NoisyImage))); %Standard Deviation of the Noisy Image
SNR_NoisyImage = Mean/SD; % SNR = Mean/Std. Dev.