图像处理之添加高斯与泊松噪声
2012-12-04 23:16
344 查看
数学基础:
什么是泊松噪声,就是噪声分布符合泊松分布模型。泊松分布(Poisson Di)的公
式如下:
关于泊松分布的详细解释看这里:http://zh.wikipedia.org/wiki/泊松分佈
关于高斯分布与高斯噪声看这里:
/article/1391113.html
二:程序实现
以前在图像加噪博文中现实的加高斯噪声,比较复杂。是自己完全实现了高斯随
机数的产生,这里主要是利用JAVA的随机数API提供的nextGaussion()方法来得
到高斯随机数。泊松噪声为了简化计算,Google到一位神人完成的C++代码于是
我翻译成Java的。
三:程序效果
滤镜源代码:
本文出自 “流浪的鱼” 博客,请务必保留此出处http://gloomyfish.blog.51cto.com/8837804/1400317
什么是泊松噪声,就是噪声分布符合泊松分布模型。泊松分布(Poisson Di)的公
式如下:
关于泊松分布的详细解释看这里:http://zh.wikipedia.org/wiki/泊松分佈
关于高斯分布与高斯噪声看这里:
/article/1391113.html
二:程序实现
以前在图像加噪博文中现实的加高斯噪声,比较复杂。是自己完全实现了高斯随
机数的产生,这里主要是利用JAVA的随机数API提供的nextGaussion()方法来得
到高斯随机数。泊松噪声为了简化计算,Google到一位神人完成的C++代码于是
我翻译成Java的。
三:程序效果
滤镜源代码:
package com.gloomyfish.filter.study; import java.awt.image.BufferedImage; import java.util.Random; public class NoiseAdditionFilter extends AbstractBufferedImageOp { public final static double MEAN_FACTOR = 2.0; public final static int POISSON_NOISE_TYPE = 2; public final static int GAUSSION_NOISE_TYPE = 1; private double _mNoiseFactor = 25; private int _mNoiseType = POISSON_NOISE_TYPE; public NoiseAdditionFilter() { System.out.println("Adding Poisson/Gaussion Noise"); } public void setNoise(double power) { this._mNoiseFactor = power; } public void setNoiseType(int type) { this._mNoiseType = type; } @Override public BufferedImage filter(BufferedImage src, BufferedImage dest) { int width = src.getWidth(); int height = src.getHeight(); Random random = new Random(); if ( dest == null ) dest = createCompatibleDestImage( src, null ); int[] inPixels = new int[width*height]; int[] outPixels = new int[width*height]; getRGB( src, 0, 0, width, height, inPixels ); int index = 0; for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { index = row * width + col; ta = (inPixels[index] >> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; if(_mNoiseType == POISSON_NOISE_TYPE) { tr = clamp(addPNoise(tr, random)); tg = clamp(addPNoise(tg, random)); tb = clamp(addPNoise(tb, random)); } else if(_mNoiseType == GAUSSION_NOISE_TYPE) { tr = clamp(addGNoise(tr, random)); tg = clamp(addGNoise(tg, random)); tb = clamp(addGNoise(tb, random)); } outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb; } } setRGB( dest, 0, 0, width, height, outPixels ); return dest; } private int addGNoise(int tr, Random random) { int v, ran; boolean inRange = false; do { ran = (int)Math.round(random.nextGaussian()*_mNoiseFactor); v = tr + ran; // check whether it is valid single channel value inRange = (v>=0 && v<=255); if (inRange) tr = v; } while (!inRange); return tr; } public static int clamp(int p) { return p > 255 ? 255 : (p < 0 ? 0 : p); } private int addPNoise(int pixel, Random random) { // init: double L = Math.exp(-_mNoiseFactor * MEAN_FACTOR); int k = 0; double p = 1; do { k++; // Generate uniform random number u in [0,1] and let p ← p × u. p *= random.nextDouble(); } while (p >= L); double retValue = Math.max((pixel + (k - 1) / MEAN_FACTOR - _mNoiseFactor), 0); return (int)retValue; } }转载文章请注明
本文出自 “流浪的鱼” 博客,请务必保留此出处http://gloomyfish.blog.51cto.com/8837804/1400317
相关文章推荐
- 图像处理之添加高斯与泊松噪声
- 图像处理------添加高斯与泊松噪声 分类: 视频图像处理 2015-07-24 14:58 61人阅读 评论(0) 收藏
- 图像处理------添加高斯与泊松噪声
- 图像处理------添加高斯与泊松噪声
- 图像处理------添加高斯与泊松噪声
- 图像处理之添加高斯与泊松噪声
- 图像处理之添加高斯与泊松噪声
- 图像处理基础(1):噪声的添加和过滤
- 图像处理之每日一练:噪声的添加和过滤
- 用OpenCV的RNG类为图像添加高斯噪声
- 数字图像处理_高斯噪声_纯C
- 图像添加高斯噪声、胡椒噪声、盐噪声和椒盐噪声
- 图像处理(七)给图像添加噪声
- 为图像添加椒盐噪声和高斯噪声
- 图像处理基础(1):噪声的添加和过滤
- 使用opencv给图像添加高斯噪声
- opencv 降低图像亮度 + 添加噪声处理
- 图像处理之噪声---椒盐,白噪声,高斯噪声三种不同噪声的区别
- 怎样在不处理的情况下在ABBYY FineReader 12中添加图像
- 利用pytorch实现Fooling Images(添加特定噪声到原始图像,使神经网络误识别)