MatlabCode

本站所有资源均为高质量资源,各种姿势下载。

您现在的位置是:MatlabCode > 资源下载 > 图像处理 > 给图像添加高斯、椒盐、加性及乘性噪声(噪声生成)

给图像添加高斯、椒盐、加性及乘性噪声(噪声生成)

资 源 简 介

matlab给图像添加高斯、椒盐、加性及乘性噪声(噪声生成)源代码Free Source Code for Adds diferent types of noise to an image

详 情 说 明

以下是使用Matlab给图像添加高斯、椒盐、加性和乘性噪声的源代码。这些噪声类型可以用于对图像进行处理和增强。您可以自由使用这些源代码,以在图像中添加不同类型的噪声。

```matlab

% 高斯噪声

function noisyImage = addGaussianNoise(image, mean, variance)

% 在图像中生成高斯噪声

noise = mean + sqrt(variance) * randn(size(image));

noisyImage = double(image) + noise;

end

% 椒盐噪声

function noisyImage = addSaltAndPepperNoise(image, density)

% 在图像中生成椒盐噪声

noisyImage = image;

[rows, cols] = size(image);

numPixels = round(density * rows * cols);

% 在随机位置添加椒盐噪声

for i = 1:numPixels

row = randi(rows);

col = randi(cols);

noisyImage(row, col) = randi([0, 255]);

end

end

% 加性噪声

function noisyImage = addAdditiveNoise(image, strength)

% 在图像中生成加性噪声

noise = strength * randn(size(image));

noisyImage = double(image) + noise;

end

% 乘性噪声

function noisyImage = addMultiplicativeNoise(image, strength)

% 在图像中生成乘性噪声

noise = 1 + (strength * (rand(size(image)) - 0.5));

noisyImage = double(image) .* noise;

end

% 调用示例

image = imread('image.jpg');

gaussianNoisyImage = addGaussianNoise(image, 0, 100);

saltAndPepperNoisyImage = addSaltAndPepperNoise(image, 0.01);

additiveNoisyImage = addAdditiveNoise(image, 50);

multiplicativeNoisyImage = addMultiplicativeNoise(image, 0.1);

```

这些源代码可以帮助您在Matlab中对图像进行噪声处理,并实现不同类型噪声的添加。