### How To Make Exponential Noise On Image – C# Guide

Exponential noise is one of the noise models we can use to simulate corruption of data. This guide show how to use it on images.

Filter by Category

- C# Tutorial(85)
- C# Image Processing(69)
- Morphological Processes(20)
- Image Processing(16)
- Image Restoration and Reconstruction(16)
- Image Segmentation(13)
- C# Data Structures And Algorithms(11)
- Color Image Processing(8)
- Frequency Domain Filtering(8)
- Image Noise(6)
- Grayscale Morphology(5)
- Thresholding(4)
- Order-Statistic Filters(4)
- Mean Filters(4)
- Sorting Algorithms(4)
- Morphological Reconstruction(3)
- Edge Detection(3)
- Simple Lists(2)
- RGB to HSI Color Model(2)
- Adaptive Filters(2)
- Tone and Color Corrections(2)
- Linked Lists(2)
- Stacks(1)
- Queues(1)
- Point Detection(1)
- Line Detection(1)
- C# Arrays(1)
- Region Segmentation Using Superpixels(1)
- Region Segmentation With K Means Clustering(1)
- Region Splitting And Merging(1)
- Sorted Lists(1)
- Region Growing Segmentation(1)
- Digital Image Watermarking(1)
- Using Color In Image Segmentation(1)
- Social Games(1)
- Bandreject Filters(1)
- Bandpass filters(1)
- Notch Filters(1)
- Landing Pages(1)
- Intensity Slicing and Color Coding(1)
- Color Slicing(1)
- Histogram Processing Color Images(1)
- Color Image Smoothing And Sharpening(1)
- C# Basics(1)

How To Make Exponential Noise On Image...

Exponential noise is one of the noise models we can use to simulate data corruption. In our case here, we’ll use it on images. Therefore, we will use its probability distribution function to create an image histogram and from it, noise we will add to our original image.

We encounter noise in images when we’re acquiring it. The most common reasons for it are low grade equipment and environment conditions. I other words, if we use an old camera, photos we take can end up corrupted because of lightning, temperature changes and anything that physically impacts sensors.

Exponential noise is a special case of gamma or Erlang noise where *b* parameters equals to 1. If we take a look at the formula for gamma noise probability distribution function and input parameter *b*.

We can see that basically by eliminating the effect of parameter *b*, the formula for exponential noise probability distribution becomes much simpler. However, it makes the shape of the distribution curve less controlable, since we have only one parameter left for that.

Let’s clear up what the other parameters in the formula represent. Firstly, *z* variable represents intensity value. Secondly, *a* parameter is the factor, with which we can control the shape of the exponential function curve. And lastly, *e* is the Eulers constant, which is 2.71828.

As we mentioned earlier, we will create an image histogram from the probability distribution function. Once we distributed intensity values among the pixels of the noise image we will add them to our original image te make the image noisy.

I’ll break it down what this function actually does to image data. First step is to calculate the probability distribution across all intensities. Secondly, it takes that data and divides each probability with the sum of all computed probabilities.

Furthermore, we take those normalized probabilites and multiply them by the number of pixel values original image has. After that, we take all those distributed values, put them in an array and scramble it.

```
public static Bitmap ExponentialNoise(this Bitmap image)
{
int w = image.Width;
int h = image.Height;
```` BitmapData image_data = image.LockBits(`

` new Rectangle(0, 0, w, h),`

` ImageLockMode.ReadOnly,`

` PixelFormat.Format24bppRgb);`

` int bytes = image_data.Stride * image_data.Height;`

` byte[] buffer = new byte[bytes];`

` byte[] result = new byte[bytes];`

` Marshal.Copy(image_data.Scan0, buffer, 0, bytes);`

` image.UnlockBits(image_data);`

` byte[] noise = new byte[bytes];`

` double[] erlang = new double[256];`

` double a = 5;`

` Random rnd = new Random();`

` double sum = 0;`

` for (int i = 0; i < 256; i++)`

` {`

` double step = (double)i * 0.01;`

` if (step >= 0)`

` {`

` erlang[i] = (double)(a * Math.Exp(-a * step));`

` }`

` else`

` {`

` erlang[i] = 0;`

` }`

` sum += erlang[i];`

` }`

` for (int i = 0; i < 256; i++)`

` {`

` erlang[i] /= sum;`

` erlang[i] *= bytes;`

` erlang[i] = (int)Math.Floor(erlang[i]);`

` }`

` int count = 0;`

` for (int i = 0; i < 256; i++)`

` {`

` for (int j = 0; j < (int)erlang[i]; j++)`

` {`

` noise[j + count] = (byte)i;`

` }`

` count += (int)erlang[i];`

` }`

` for (int i = 0; i < bytes - count; i++)`

` {`

` noise[count + i] = 0;`

` }`

` noise = noise.OrderBy(x => rnd.Next()).ToArray();`

` for (int i = 0; i < bytes; i++)`

` {`

` result[i] = (byte)(buffer[i] + noise[i]);`

` }`

` Bitmap result_image = new Bitmap(w, h);`

` BitmapData result_data = result_image.LockBits(`

` new Rectangle(0, 0, w, h),`

` ImageLockMode.WriteOnly,`

` PixelFormat.Format24bppRgb);`

` Marshal.Copy(result, 0, result_data.Scan0, bytes);`

` result_image.UnlockBits(result_data);`

` return result_image;`

` }`

This guide shows how to make a noisy image. Furthermore, making noise artificially give us opportunity to study image restoration and reconstruction techniques.

You can **download** the entire project and play with the values yourself.