博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(原創) 如何對圖片加入Salt and Pepper Noise? (.NET) (C/C++) (C++/CLI) (GDI+) (Image Processing)...
阅读量:7218 次
发布时间:2019-06-29

本文共 1519 字,大约阅读时间需要 5 分钟。

Salt and Pepper的公式如下

None.gif
I(nim
,
 i
,
 j) 
=
 
0
 if uniform(
0
,
 
1
) < salt
None.gifI(nim
,
 i
,
 j) 
=
 
255
 if uniform(
0
,
 
1
) > 
1
 - pepper
None.gifI(nim
,
 i
,
 j) 
=
 I(im
,
 i
,
 j) otherwise
None.gif
None.gifuniform(
0
,
 
1
) : ramdom variable uniformly distributed over
[
0, 1
]
 1
ExpandedBlockStart.gif
ContractedBlock.gif
/**/
/* 
 2InBlock.gif(C) OOMusou 2006 http://oomusou.cnblogs.com
 3InBlock.gif
 4InBlock.gifFilename    : SaltAndPepperNoise.cpp
 5InBlock.gifCompiler    : Visual C++ 8.0 / C++/CLI
 6InBlock.gifDescription : Demo how to process Salt and Pepper Noise
 7InBlock.gifRelease     : 12/20/2006 1.0
 8ExpandedBlockEnd.gif*/
 9
None.gif
10
None.gif#include 
"
stdafx.h
"
11
None.gif#include 
"
stdlib.h
"
12
None.gif
13
None.gif
using
 
namespace
 System::Drawing;
14
None.gif
using
 
namespace
 System::Drawing::Imaging;
15
None.gif
16
None.gif
void
 saltpepperNoise(Bitmap
^
, Bitmap
^
double&
double&
);
17
None.gif
18
ExpandedBlockStart.gifContractedBlock.gif
int
 main() 
dot.gif
{
19InBlock.gif   // Read lena.jpg
20InBlock.gif  Bitmap^ oriImg = gcnew Bitmap("lena.jpg");
21InBlock.gif  // Declare Gaussian image for lena.jpg
22InBlock.gif  Bitmap^ spImg = gcnew Bitmap(oriImg->Width, oriImg->Height);
23InBlock.gif
24InBlock.gif  // Salt-and-Pepper noise with salt rate=5% and pepper rate=5%
25InBlock.gif  double salt = 0.05, pepper = 0.05;
26InBlock.gif  saltpepperNoise(oriImg, spImg, salt, pepper);
27InBlock.gif  spImg->Save("lena_saltpepper.jpg");
28InBlock.gif
29InBlock.gif  return 0;
30InBlock.gif
31ExpandedBlockEnd.gif}
32
None.gif
33
ExpandedBlockStart.gifContractedBlock.gif
void
 saltpepperNoise(Bitmap
^
 oriImg, Bitmap
^
 spImg, 
double&
 salt, 
double&
 pepper) 
dot.gif
{
34ExpandedSubBlockStart.gifContractedSubBlock.gif  for(int y = 0; y != oriImg->Height; ++y) dot.gif{
35ExpandedSubBlockStart.gifContractedSubBlock.gif    for(int x = 0; x != oriImg->Width; ++x) dot.gif{
36InBlock.gif      double val = (double)rand() / RAND_MAX;
37InBlock.gif
38ExpandedSubBlockStart.gifContractedSubBlock.gif      if (val < salt) dot.gif{
39InBlock.gif        spImg->SetPixel(x, y, Color::Black);
40ExpandedSubBlockEnd.gif      }
41ExpandedSubBlockStart.gifContractedSubBlock.gif      else if (val > 1-pepper) dot.gif{
42InBlock.gif        spImg->SetPixel(x, y, Color::White);
43ExpandedSubBlockEnd.gif      }
44ExpandedSubBlockStart.gifContractedSubBlock.gif      else dot.gif{
45InBlock.gif        spImg->SetPixel(x, y, oriImg->GetPixel(x, y));
46ExpandedSubBlockEnd.gif      }
47ExpandedSubBlockEnd.gif    }
48ExpandedSubBlockEnd.gif  }
49ExpandedBlockEnd.gif}

原圖

執行結果

转载地址:http://dnxym.baihongyu.com/

你可能感兴趣的文章
python开发mysql:视图、触发器、事务、存储过程、函数
查看>>
Oracle Enterprise Manager (OEM)的基本命令行控制(based on 11g)
查看>>
day5-configparser模块
查看>>
委托的N种写法,你喜欢哪种?
查看>>
nginx基本调优
查看>>
laravel性能优化技巧(转)
查看>>
使用zsh 替换 bash
查看>>
TensorFlow+实战Google深度学习框架学习笔记(12)------Mnist识别和卷积神经网络LeNet...
查看>>
计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接(ZT)
查看>>
四则运算2
查看>>
八 条件判断
查看>>
卷积神经网络
查看>>
中文操作系统XP出现乱码(各种软件)
查看>>
书籍列表
查看>>
STL源码分析-heap部分
查看>>
shell命令行执行python(解析json)
查看>>
什么是web service?为什么要用webservice?什么时候用web service??
查看>>
简单的drag和drop,不是jquery的draggable
查看>>
用 js 写一个获取随机颜色的程序
查看>>
【转】Unity中的协同程序-使用Promise进行封装(一)
查看>>