MATLAB中给图像加高斯噪声时imnoise的方差参数问题

在经过仔细阅读文档后发现,其实MATLAB的说明文档已经写得很清楚,现摘出如下:

J = imnoise(I,type,parameters) Depending on type, you can specify additional parameters to imnoise 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 . All numerical parameters are normalized— they correspond to operations with images with intensities ranging from 0 to 1.

其中最关键的就是 normalized,即归一化,方差值在0~1之间。这时才想起来,关于gaussian参数的说明:

J = imnoise(I,‘gaussian’,M,V) adds Gaussian white noise of mean m and variance v to the image I. The default is zero mean noise with 0.01 variance.

即默认的M,V值分别为0, 0.01(注意此处的方差形式)。

所以最终的结论就是 需要对方差归一化处理 ,比如此处要对一幅256*256的图像加入标准偏差为10的高斯噪声,那么相应的语句应为:

J = imnoise(I, ‘gaussian’, 0, 102/2552)

可以按照以下步骤在MATLAB中给图像高斯噪声和椒盐噪声: 1. 使用imread函数读取原始图像,将其赋值给一个矩阵变量,例如img: ```matlab img = imread('image.jpg'); ``` 2. 使用imnoise函数添高斯噪声: ```matlab noisy_img_gauss = imnoise(img, 'gaussian', 0, 0.01); ``` 其中,'gaussian'表示添高斯噪声,0表示噪声均值,0.01表示噪声方差。可以根据实际情况更改均值和方差。 3. 使用imnoise函数添椒盐噪声: ```matlab noisy_img_salt_pepper = imnoise(img, 'salt & pepper', 0.05); ``` 其中,'salt & pepper'表示添椒盐噪声,0.05表示噪声密度,即噪声像素占总像素的比例。可以根据实际情况更改噪声密度。 4. 使用imshow函数显示添噪声后的图像: ```matlab subplot(1,3,1),imshow(img),title('原始图像'); subplot(1,3,2),imshow(noisy_img_gauss),title('添高斯噪声后的图像'); subplot(1,3,3),imshow(noisy_img_salt_pepper),title('添椒盐噪声后的图像'); ``` 这里使用subplot函数将原始图像、添高斯噪声后的图像和添椒盐噪声后的图像都显示在同一窗口中,方便比较和观察。 完整代码示例: ```matlab img = imread('image.jpg'); noisy_img_gauss = imnoise(img, 'gaussian', 0, 0.01); noisy_img_salt_pepper = imnoise(img, 'salt & pepper', 0.05); subplot(1,3,1),imshow(img),title('原始图像'); subplot(1,3,2),imshow(noisy_img_gauss),title('添高斯噪声后的图像'); subplot(1,3,3),imshow(noisy_img_salt_pepper),title('添椒盐噪声后的图像'); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值