Noise 2015-04-26

Image noise is a random variation of a pixels colour, that degrades the image quality. This degradation is often a desired effect in order to make an image look older or taken by a different camera, however is is mostly an unwanted artefact of the image. Stet.io has filters to both add and remove noise from images, as explained below.

Noise reduction can be achieved by running a mean or median filter on the image, depending on the type of noise present. Gaussian like noise, is best removed by the mean filter whereas salt and pepper like noise is best removed by the median filter. These are the noise generation and reduction filters are present in Stet.io.

Gaussian noise is a Gaussian random variation of a pixels colour from the true value that is present in every pixel. This is coded as below, assuming the Gaussian(mean, variation) function returns a Gaussian distributed random number distributed about the mean value. (See the stet image representation if the code isn't clear).

for(var byte in image)
{
image[byte] = Gaussian(image[byte], variation);
image[byte + 1] = Gaussian(image[byte + 1], variation);
image[byte + 2] = Gaussian(image[byte + 2], variation);
}

Gaussian noise is best reduced by replacing the value of a pixel with the mean or average of the pixel's neighbours.

Salt and pepper noise is so called due to the present of white (salt) and black (pepper) pixels randomly in the image. In this form of noise the pixel is either white, black or the true value as shown below.

for(var byte in image)
{
if(random < noise_probability)
{
if(random2 < 0.5)
{
image[byte] = 255;
image[byte + 1] = 255;
image[byte + 2] = 255;
}
else
{
image[byte] = 0;
image[byte + 1] = 0;
image[byte + 2] = 0;
}
}
}

Salt and pepper noise is best reduced by replacing the value of a pixel with the median of the pixel's neighbours.

Back to blog