图像处理之添加高斯与泊松噪声
来源:互联网 发布:wireshark过滤端口抓包 编辑:程序博客网 时间:2024/04/26 14:08
from: http://blog.csdn.net/jia20003/article/details/8258052
数学基础:
什么是泊松噪声,就是噪声分布符合泊松分布模型。泊松分布(Poisson Di)的公
式如下:
关于泊松分布的详细解释看这里:http://zh.wikipedia.org/wiki/泊松分佈
关于高斯分布与高斯噪声看这里:
http://blog.csdn.net/jia20003/article/details/7181463
二:程序实现
以前在图像加噪博文中现实的加高斯噪声,比较复杂。是自己完全实现了高斯随
机数的产生,这里主要是利用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;
- }
- }
版权声明:本文为博主原创文章,未经博主允许不得转载。
- 上一篇Java Socket编程 - 基于TCP方式的二进制文件传输
- 下一篇Java Socket编程 - 基于Socket实现HTTP下载客户端
- 顶
- 1
- 踩
- 0
- 主题推荐
- 图像处理
- 猜你在找
- JavaScript for Qt Quick(QML)
- Java Swing、JDBC开发桌面级应用
- JavaScript DOM编程
- Citrix Provisioning Services 7.1 管理
- Flash实战技能应用从入门到精通
查看评论
- 5楼 CRAZYDooo2015-04-29 21:36发表 [回复]
- 楼主,看完了你的博客,感觉每篇都有用到一些未给出定义的方法,想看下具体实施过程,能给一下完整的代码吗?
我的邮箱:
iltvxqsj@163.com
谢谢!
- 4楼 u0111353082014-12-20 14:05发表 [回复]
- 最近在学数字图像处理,看了你的代码有好多函数不知道作用是什么,楼主可以给我发一份完整的代码吗?邮箱490349699@qq.com,谢谢!
- 3楼 xchang19852014-02-17 12:39发表 [回复]
- 你好,一直在浏览您的博客,您的代码对我java的图像处理毕业设计很有用,麻烦您吧AbstractBufferedImageOp 类发我一份吗,谢谢514506915@qq.com
- 2楼 青石桥边2014-02-09 15:44发表 [回复]
- 你好,我正在做关于图像去噪的毕设,想请您给我发一份AbstractBufferedImageOp 类,感觉您的这个类应该是在读取图片,但我不知道具体怎么写,有时间的话麻烦您给我发lg920810@163邮箱 非常感谢!
- Re: gloomyfish2014-02-10 10:10发表 [回复]
- 晚上发你回复u013124795:
- Re: apocalypse_joe2014-02-11 21:15发表 [回复]
- 回复jia20003:楼主你好 读了你的博客收获很大 但理解能力有限、想看下完整的代码 同求AbstractBufferedImageOp 类 邮箱是1269670921@qq.com 再次感谢
- Re: gloomyfish2014-02-17 14:48发表 [回复]
- 发给你啦!回复u010278682:
- 1楼 xiaojidan20112012-12-25 10:50发表 [回复] [引用][举报]
- 楼主 有c代码的吗
0 0
- 图像处理之添加高斯与泊松噪声
- 图像处理之添加高斯与泊松噪声
- 图像处理------添加高斯与泊松噪声
- 图像处理-图像添加高斯噪声并滤波
- 图像中添加高斯噪声
- randn()给图像添加高斯噪声
- 为图像添加椒盐噪声和高斯噪声
- 图像添加高斯噪声、胡椒噪声、盐噪声和椒盐噪声
- C#图像添加高斯噪声和椒盐噪声及图像恢复
- 对一幅图像添加高斯噪声
- 图像模拟添加(产生)高斯噪声的OpenCV代码!
- 向图像添加高斯噪声(Vc++)
- 使用opencv给图像添加高斯噪声
- matlab 图像加入高斯噪声和平滑处理练习
- 基于matlab的图像处理——高斯噪声&均值滤波,椒盐噪声&中值滤波
- 噪声添加(高斯噪声、椒盐噪声)
- 图像处理中的线性滤波算法与非线性滤波算法的区别、高斯噪声与椒盐噪声的区别及各自的特点
- opencv 降低图像亮度 + 添加噪声处理
- Android:Material Design on Android Checklist!
- 配置git for eclipse
- 图像处理之应用篇-大米计数续
- hook对应的汇编码0x8B, 0xFF,0x55,0x8B, 0xEC, // mov ebp,esp
- 错误1error LNK2019: 无法解析的外部符号 __imp____glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用D:\C+
- 图像处理之添加高斯与泊松噪声
- diamond types are not supported at this language level
- CentOS-minimal 6.5 安装mysql
- spring aop的案例(二)缓存配置
- 异常情况下Activity生命周期分析
- C#: 向Word插入排版精良的Text Box
- AndroidUI-TxetView嵌套Html的使用
- POJ2488 dfs回溯
- 最全的常用正则表达式大全——包括校验数字、字符、一些特殊的需求等等