Add Gaussian, Salt and Pepper, Additive and Multiplicative Noise to Images (Noise Generation)
- Login to Download
- 1 Credits
Resource Overview
Detailed Documentation
This MATLAB source code demonstrates how to add various types of noise to images, including Gaussian, salt and pepper, additive, and multiplicative noise. These noise generation techniques are essential for image processing tasks such as algorithm testing, robustness evaluation, and image enhancement studies. You can freely use this source code to incorporate different noise types into your images.
```matlab
% Gaussian Noise Function
function noisyImage = addGaussianNoise(image, mean, variance)
% Generates Gaussian noise with specified mean and variance
% Uses randn() function to create normally distributed random noise
noise = mean + sqrt(variance) * randn(size(image));
noisyImage = double(image) + noise;
end
% Salt and Pepper Noise Function
function noisyImage = addSaltAndPepperNoise(image, density)
% Creates salt and pepper noise with specified pixel corruption density
% Randomly selects pixels and assigns random intensity values (0-255)
noisyImage = image;
[rows, cols] = size(image);
numPixels = round(density * rows * cols);
% Adds noise at random pixel positions using randi() for random indexing
for i = 1:numPixels
row = randi(rows);
col = randi(cols);
noisyImage(row, col) = randi([0, 255]);
end
end
% Additive Noise Function
function noisyImage = addAdditiveNoise(image, strength)
% Generates additive noise by directly adding random values to pixels
% Strength parameter controls the amplitude of the added noise
noise = strength * randn(size(image));
noisyImage = double(image) + noise;
end
% Multiplicative Noise Function
function noisyImage = addMultiplicativeNoise(image, strength)
% Creates multiplicative noise that scales pixel values
% Uses uniform distribution (rand()) centered around 1
noise = 1 + (strength * (rand(size(image)) - 0.5));
noisyImage = double(image) .* noise;
end
% Usage Example
image = imread('image.jpg');
gaussianNoisyImage = addGaussianNoise(image, 0, 100);
saltAndPepperNoisyImage = addSaltAndPepperNoise(image, 0.01);
additiveNoisyImage = addAdditiveNoise(image, 50);
multiplicativeNoisyImage = addMultiplicativeNoise(image, 0.1);
```
This comprehensive source code provides practical implementations of four fundamental noise types commonly used in image processing research. The algorithms demonstrate proper use of MATLAB's random number generation functions (randn and rand) and matrix operations for efficient noise addition. Each function includes clear parameter controls for adjusting noise characteristics.
- Login to Download
- 1 Credits