【图像安全性分析】噪声攻击MATLAB代码

【高斯噪声】

I=imread('coins.png');

J=imnoise(I, 'gaussian', 0, 0.01);%方差为0.01的高斯噪声

K=imnoise(I, 'gaussian', 0, 0.03);%方差为0.03的高斯噪声

figure;

subplot(121);  imshow(J);title('方差为0.01的高斯噪声')

subplot(122);  imshow(K);title('方差为0.03的高斯噪声')

【椒盐噪声】

I=imread('cameraman.tif');

I=im2double(I);

J=imnoise(I, 'salt & pepper', 0.01);%添加密度为0.01的椒盐噪声

K=imnoise(I, 'salt & pepper', 0.03);%添加密度为0.03的椒盐噪声

figure;

subplot(121);  imshow(J);title('%添加密度为0.01的椒盐噪声');

subplot(122);  imshow(K);title('%添加密度为0.03的椒盐噪声');

【泊松噪声】

clear all; close all;

I=imread('cameraman.tif');

J=imnoise(I, 'poisson');%添加泊松噪声

figure;

subplot(121);  imshow(I);title('原图');

subplot(122);  imshow(J);title('添加泊松噪声后的图像');

【乘性噪声】

clear all; close all;

I=imread('cameraman.tif');

J=imnoise(I, 'speckle');%添加方差为0.04的乘性噪声

K=imnoise(I, 'speckle', 0.5);%添加方差为0.5的乘性噪声

figure;

subplot(121);  imshow(J);title('添加方差为0.04的乘性噪声');

subplot(122);  imshow(K);title('添加方差为0.5的乘性噪声');