Image Processing in C#: Part 11 - Getting That Old-time Effect with Sepia

Back in the old days, and here I am talking about the 19th century old days, it was very common to apply a sepia tinting to photographs. This was a chemical process, which preserved the photos for longer, although it was also used for its aesthetic appeal. These days, with digital photograpy, we don’t need to preserve photos like in those early days, but it still does give a nice warm tone to a photo, and is great for making a modern photo appear old-fashioned.

Converting a photo to sepia is a relatively easy effect. For each pixel in the image, we first convert the pixel to greyscale. We then add a value to the green component, and double that value to the red component to give the sepia effect.

The depth of the sepia effect is determined by this value, which we pass here as a parameter. A value of 0 will give a standard greyscale image.
Read More »

Image Processing in C#: Part 10 - Embossing

One of the most striking effects to apply to an image is embossing. This is effect is a form of edge-detection, and is also done using convolution, which you can read more about on my post on smoothing using convolution.

The convolution grid we use in embossing is a little different to the others we have looked at so far. It has an offset of 127, and a fixed factor of 4. The offset makes the the image appear on average as a medium gray.

The grid we will use then is

-10-1
040
-10-1

Read More »

Image Processing in C#: Part 9 - Applying a Mean Removal

Another type of sharpening effect is mean removal. It works similarly to the standard sharpening, except it subtracts values from all the surrounding pixels evenly.

The grid which we used for this effect is as follows

-1-1-1
-111-1
-1-1-1

This gives a much more noticeable sharpening effect on the image.
Read More »

Image Processing in C#: Part 8 - Sharpening an Image

Sharpening an image is merely the inverse of what we did to blur the image. It also uses the convolution function, which you can read in my post about smoothing using convolution.

Here we supply a convolution matrix set up as follows:

0-20
-211-2
0-20

Here our weighting factor would total 3, since the negative numbers get subtracted from the weighting total.
Read More »

Image Processing in C#: Part 7 - Applying a Gaussian Blur

Gaussian blur also uses convolution to create the effect. If you have not yet read my blog post on smoothing using convolution, I would advise you to read that post first, as in that post I explain how the convolution function works.

Gaussian blur works very similarly to the smoothing function, in that both are a type of blur, but the Gaussian blur gives a more natural looking blur. It achieves this by not have a flat weighting, but instead has a weighting based on a Gaussian curve, thus for our 3x3 grid, the values we want to supply the convolution function is as follows:
Read More »

Image Processing in C#: Part 6 - Smoothing Using Convolution

Smoothing, which is just a type of blurring is based on a concept called convolution. How this works is that you take a square section of pixels, often 3x3 but can be any size, although the larger you make the grid, the less pixels that will get affected by the effect around the edges.

The centre pixel of the grid is the main pixel we are interested in. To use convolution, what we do is assign weightings to each pixel in the grid, depending on what effect we are trying to achieve, and then assign the result to the centre pixel.

The basic data structure we use for the convolution is a class which contains the 2D array, as well as a weighting factor, and an offset.
Read More »

Image Processing in C#: Part 5 - Adjusting the Gamma

Gamma correction has a history based on the properties of CRT’s and was first noted in televisions.

The light intensity of a CRT is not directly proportional to the input voltage, but is rather proportional to the input voltage raised to a particular power. This power was known as gamma, and varied with CRT. The value was usually around 2.5.

This means that different CRT’s (televisions and monitors before the flatscreen days) all showed the same images slightly differently, and gamma correction was implement to correct this.

A gamma filter works by creating an array of 256 values called a gamma ramp for each value of the red, blue and green components. The gamma value must be between 0.2 and 5.

The formula for calculating the gamma ramp is 255 * (i / 255)1/gamma + 0.5.

If this value is greater than 255, then it is clamped to 255. It is possible to have a different gamma value for each of the 3 colour components.

Then for each pixel in the image, we can substitute the value in this array for the original value of that component at that pixel.
Read More »

Image Processing in C#: Part 4 - Contrast

Contrast in a picture is a measure of how close the range of colours in a picture are. The closer the colours are together, the lower the contrast.

The value for the contrast ranges from -100 to 100, with positive numbers increasing the contrast, and negative numbers decreasing the contrast.

Now, we calculate the contrast value which we will use in the calculation with ((100 + contrast) / 100)

Then, for each pixel in the image, we take each component of the pixel, and divide the value by 255 to get a value between 0 and 1. We then subtract 0.5, and any values which are negative will have their contrast decreased, while any positive values will have their contrast increased.

We then add back the 0.5, and convert the value back to a range of 0-255. After that we set the pixel colour again.
Read More »

Image Processing in C#: Part 3 - Adjusting the Brightness

To increase the brightness of an image, all you need to do is add a value to each component for each pixel in the image.

Increasing the brightness is not always reversible, because as the colour value tops out at 255, if the increased value goes above this value, it will be limited to that value. This makes any reversal of the process impossible. The opposite is true for negative values. Then if the value falls below 0, then the values are limited.
Read More »

Image Processing in C#: Part 2 - Converting an Image to Greyscale

Converting an image to greyscale is a relatively easy effect to apply to an image. For each pixel in the image, we take the three colour components (red, green and blue), and then combine the values.

Most people would think that you just take the average of the three colours, but the problem with that is the human eye has different sensitivities to different frequencies, so what we need to do is add in the colours at different ratios.

So, to make the colour ratios correct, we multiply the red, green and blue components by 0.299, 0.587 and 0.114 respectively. We then assign the value to all the components of the pixel.
Read More »

Tag Cloud

Algorithms (3) Android (10) Astronomy (25) Audio (1) Audiobooks (1) Barcodes (9) C# (69) Css (1) Deep sky (6) Esoteric languages (3) Family (3) Fractals (10) Gaming (1) Genealogy (14) General (2) Geodesy (3) Google (1) Graphics (3) Hubble (2) Humour (1) Image processing (23) Java (8) Javascript (5) jQuery (3) Jupiter (3) Maths (22) Moon (5) Music (4) Pets (5) Programming (88) Saturn (1) Science (1) Spitzer (4) Sun (4) Tutorials (68) Unity (3) Web (9) Whisky (13) Windows (1) Xamarin (2)