Matlab中函数imnoise使用浅谈

噪声,简而言之就是图像中随机出现的灰度变化大的离散的像素点。噪声可能来自于图像采集,量化等过程,也可能产生于图像传送过程中,具有离散性和随机性等特点。

1.噪声的分类

根据噪声服从的分布对其进行分类:
(1)高斯噪声(Gaussian white noise):最普通的噪声,噪声信号随机分布,没有规律;
(2)泊松噪声(Poisson noise):常在亮度非常小时出现,或在高倍电子放大线路中出现,噪声信号服从Poisson分布。
(3)颗粒噪声:白噪声的一种,图像中显示明显的颗粒,最常见的便是椒盐噪声(salt & pepper noise)。

2.函数imnoise

在Matlab中有一个重要的噪声生成函数imnoise,其常见语法说明如下:

语法参数说明
J = imnoise(I,type)按照给定类型添加图像噪声给图像I
J = imnoise(I,type,parameters)parameters泛指可以添加的参数,类型不同,参数自然不同
J = imnoise(I,‘gaussian’,m,v)添加高斯白噪声,均值为m,方差为v。default状态下,m = 0,v = 0.01
J = imnoise(I,‘localvar’,V)添加零均值,局部方差为V的高斯白噪声给图像I。V是与I尺寸相同的数组
J = imnoise(I,‘poisson’)添加Poisson噪声给图像I
J = imnoise(I,‘salt & pepper’,d)添加椒盐噪声给图像I,d是噪声密度。这将影响d * numel(I)个像素。default状态下,d = 0.05
J = imnoise(I,‘speckle’,v)添加乘法噪声给图像I,v是方差。机理:J = I + n * I,n是均匀分布的随机噪声。在default状态下,v = 0.04

注意:函数imnoise在将输入图像添加噪声的过程中,若输入图像的数据类型是double型,范围为[0,1],噪声‘gaussian’,‘poisson’,‘speckle’的参数类型总是被指定;若输入图像的数据类型是uint8或uint16,imnoise函数先将图像数据类型转化成double类型,添加指定的参数,最后输出时又将数据类型还原成原输入图像数据类型。

参数说明:对于多数噪声类型,输入图像I的数据类型可以是uint8,uint16,int16,single或double。输出图像的数据类型和输入图像的数据类型相同。若I超过了2维,则将其作为多维图像处理,而不是RGB图像处理。

3.imnoise函数使用示例

代码:

I = imread('eight.tif');
subplot(221),imshow(I);
title('Original image');
J = imnoise(I,'gaussian',0,0.02);%添加高斯白噪声,均值0,方差0.02
subplot(222),imshow(J);
title('Gaussian');
K = imnoise(I,'salt & pepper',0.03);%添加椒盐噪声,密度0.03
subplot(223),imshow(K);
title('Salt & Pepper');
L = imnoise(I,'poisson');%添加Poisson噪声
subplot(224),imshow(L);
title('Poisson');

运行截图:
观察运行结果可知:椒盐噪声的强度最大,但噪声分布最稀松,高斯噪声和泊松噪声分布比较密,但高斯噪声的强度比泊松噪声的强度大。

function R = imnoise2(type, varargin) %IMNOISE2 Generates an array of random numbers with specified PDF. % R = IMNOISE2(TYPE, M, N, A, B) generates an array, R, of size % M-by-N, whose elements are random numbers of the specified TYPE % with parameters A and B. If only TYPE is included in the % input argument list, a single random number of the specified % TYPE and default parameters shown below is generated. If only % TYPE, M, and N are provided, the default parameters shown below % are used. If M = N = 1, IMNOISE2 generates a single random % number of the specified TYPE and parameters A and B. % % Valid values for TYPE and parameters A and B are: % % 'uniform' Uniform random numbers in the interval (A, B). % The default values are (0, 1). % 'gaussian' Gaussian random numbers with mean A and standard % deviation B. The default values are A = 0, B = 1. % 'salt & pepper' Salt and pepper numbers of amplitude 0 with % probability Pa = A, and amplitude 1 with % probability Pb = B. The default values are Pa = % Pb = A = B = 0.05. Note that the noise has % values 0 (with probability Pa = A) and 1 (with % probability Pb = B), so scaling is necessary if % values other than 0 and 1 are required. The noise % matrix R is assigned three values. If R(x, y) = % 0, the noise at (x, y) is pepper (black). If % R(x, y) = 1, the noise at (x, y) is salt % (white). If R(x, y) = 0.5, there is no noise % assigned to coordinates (x, y). % 'lognormal' Lognormal numbers with offset A and shape % parameter B. The defaults are A = 1 and B = % 0.25. % 'rayleigh' Rayleigh noise with parameters A and B. The % default values are A = 0 and B = 1. % 'exponent
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值