图片添加高斯噪声
这是添加高斯噪声的代码,有没有大神看看为什么这个代码只能给部分图像加噪声
private void btngauss_Click(object sender, EventArgs e)
{
if (CurBitmap != null)
{
gaussnoise gnoise = new gaussnoise();
if (gnoise.ShowDialog() == DialogResult.OK)
{
Rectangle rect = new Rectangle(0, 0, CurBitmap.Width, CurBitmap.Height);
System.Drawing.Imaging.BitmapData bmpData = CurBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, CurBitmap.PixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = CurBitmap.Width * CurBitmap.Height;
byte[] grayvalues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, grayvalues, 0, bytes);
double temp = 0;
Random r1, r2;
double v1, v2;
r1 = new Random(unchecked((int)DateTime.Now.Ticks));
r2 = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < bytes; i++)
{
do
{
v1 = r1.NextDouble();
&