“This is the 8th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

preface

Hello! Friend!!!

Thank you very much for reading haihong’s article, if there are any mistakes in the article, please point out ~

 

Self-introduction ଘ(੭, ᵕ)੭

Nickname: Haihong

Tag: programmer monkey | C++ contestant | student

Introduction: because of C language to get acquainted with programming, then transferred to the computer major, had the honor to get some national awards, provincial awards… Has been confirmed. Currently learning C++/Linux/Python

Learning experience: solid foundation + more notes + more code + more thinking + learn English well!

Add Gaussian noise

concept

Gaussian noise is a kind of noise whose probability density function obeys gaussian distribution (normal distribution). If the amplitude distribution of a noise is gaussian and its power spectral density is uniformly distributed, it is called Gaussian white noise. The second moment of Gaussian white noise is not correlated, while the first moment is constant, which refers to the correlation of successive signals in time. Gaussian white noise includes thermal noise and granular noise. Gaussian noise is used as additive white noise to generate additive white Gaussian noise in communication channel testing and modeling.

Gaussian noise is consistent with the Gaussian distribution of noise, in the digital image processing is the two-dimensional Gaussian distribution (normal distribution). So how do you add gaussian noise? Firstly, we must obtain a two-dimensional gaussian noise matrix, and finally add it to the original image. The Gaussian noise has been added.

Method 1: Use randn() function to generate Gaussian noise. Here we need to use randn() function, which is specially used to generate normal distribution data. Say randn(10,10), and then add this matrix to the original image matrix (note the scale scale)

Randn (10,10) ans = -0.3587 0.6694 0.2922 0.127-0.4399-0.2027 1.2917-1.2807 0.0522-0.2097 1.4851-0.2349-0.0809 -1.0475 0.4734-0.8012-1.3658-2.4489 1.2525-0.0725 0.1214 0.2553 0.2774-0.9508-0.3378-1.1350 0.7951-0.6749 1.2525-0.0725 0.1214 0.2553 0.2774-0.9508-0.3378-1.1350 0.7951-0.6749 0.1797-0.5646-0.7056 1.5769-0.8234 1.5896 1.5743 0.1304-0.3575-1.0971-0.2286-1.5035 1.4605 0.6227-0.6059 1.5939 0.0120-0.1012-0.9397-1.6988-2.3375 1.0503-0.2038 0.7016 0.7310-0.4053-0.0419-0.3276-0.7675 0.6319 0.3662 -1.0955-1.3164 0.1579 0.3200-0.2055 0.5508-0.6350 0.7769 1.1788 1.1854-1.0070 0.1054 1.0071 0.4267 0.6462-1.1893 -1.8829-1.2166-0.2838 1.0378 0.8280 0.9141-1.5962-0.0540 1.5489 1.0449 0.6155-0.6227 0.2447 0.2955-0.7770-0.7474 0.6233 1.3306-0.2167-0.2423 1.3778-1.0203-1.1946 0.4893 0.0451Copy the code

Code:

t=imread('a1.jpg'); [m,n,z]=size(t); Y = 0 + 0.1 * randn (m, n); % t1=double(t)/255; % plus noise t1= T1 +y; % expand the pixel range to 0--255 T1 = T1 *255; Uint8 type t1=uint8(T1); Subplot (1, 2, 1), imshow (t), title (' artwork '); Subplot (1,2,2),imshow(t1),title(' after adding gaussian noise with mean 0 and standard deviation 0.1 ');Copy the code

Effect: Method 2: Random generated Gaussian noise (this I do not understand the random generated Gaussian noise function from!) Code:

image=imread('a1.jpg'); [width,height,z]=size(image); Subplot (1, 2, 1); imshow(image); The title (' artwork '); av=0; STD = 0.1; u1=rand(width,height); u2=rand(width,height); x=std*sqrt(-2*log(u1)).*cos(2*pi*u2)+av; result1=double(image)/255+x; result1=uint8(255*result1); Subplot (1,2,2); imshow(result1); Title (' after adding gaussian noise with mean 0 and standard deviation 0.1 ');Copy the code

Effect:

Method three: use the imnoise() function code

t=imread('a1.jpg'); Imshow (t), title (' artwork '); T1 = imnoise (t, gaussian, 0,0.01); Figure,imshow(T1),title(' Add gaussian noise with mean of 0 and variance of 0.01 '); T2 = imnoise (t, gaussian, 0,0.02); Figure,imshow(T2),title(' Add Gaussian noise with mean = 0 and variance = 0.02 '); T3 = imnoise (t, gaussian, 0,0.03); Figure,imshow(t3),title(' Add Gaussian noise with mean of 0 and variance of 0.03 '); T4 = imnoise (t, "gaussian", 0.2, 0.01); Figure, IMshow (T4),title(' Add gaussian noise with mean of 0.2 and variance of 0.01 '); T5 = imnoise (t, "gaussian", 0.4, 0.01); Figure,imshow(t5),title(' Add gaussian noise with mean of 0.4 and variance of 0.01 ');Copy the code

Effect:

Note that the parameters in imnoise() are written as variances, while methods 1 and 2 are written as standard deviations.