Skip to content

Instantly share code, notes, and snippets.

@arsho
Created September 8, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsho/1390a8a886ea5e6d80a3 to your computer and use it in GitHub Desktop.
Save arsho/1390a8a886ea5e6d80a3 to your computer and use it in GitHub Desktop.
Proving SNR Improvement by averaging
% Title : Demonstration of SNR improvement by averaging
% Date : 7/9/2015
% Author : Shovon
clc;
image_object=ones(200,300,3); % (height, width)
image_size_ar=size(image_object);
image_height=image_size_ar(1);
image_width=image_size_ar(2);
% Creating the original image with uniform intensity
for i = 1:image_height
for j=1:image_width
image_object(i,j,:)=[0,0,1];
end
end
mean=0; % set noise mean
var=0.2; % set noise variance
k=5; % set number of images
% Subplotting the original image
subplot(k+2,1,1);
imshow(image_object);
title('Original Image');
first_noisy_image=imnoise(image_object,'gaussian',mean,var);
sum_image=first_noisy_image;
subplot(k+2,1,2); % (row,col,pos)
imshow(first_noisy_image);
title('Noisy Image');
for i=2:k
temp_noisy_image=imnoise(image_object,'gaussian',mean,var);
subplot(k+2,1,i+1); % (row,col,pos)
imshow(temp_noisy_image);
title('Noisy Image');
sum_image=sum_image+temp_noisy_image;
end
average_image=sum_image/k;
psignal=std(image_object(:)); % author: Shovon
pnoise=std(average_image(:));
calculated_snr=10*log10(psignal/pnoise);
disp(calculated_snr);
subplot(k+2,1,k+2); % (row,col,pos)
imshow(average_image);
title(calculated_snr);
@shudarshon
Copy link

smashing code. it helped me also in my semester assignment :) i recommend you to use red color instead of blue one.

@shanto-roy
Copy link

that's a good one... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment