How To Color Histogram Equalization With C#
This guide shows how to apply color histogram equalization with iterative equalization of the image by using nth root or nth power.
Filter by Category
This guide shows how to apply color histogram equalization with iterative equalization of the image by using nth root or nth power.
Color balancing is one of the processes we use to adjust images, which are either on the weaker or heavier side for any of the color channels.
This guide shows how to apply image tone corrections for flat, dark and light images. The purpose of it is to adjust brightness and contrast.
Color slicing is a color image processing technique, which only shows colors in a certain color space making objects stand out.
False color or pseudocolor image processing coupled with intensity slicing is useful for emphasizing shapes that might be hidden to our eyes.
This guide shows how to convert RGB to HSI image data and also how to convert it back from HSI to RGB to make it displayable on screen.
Adaptive median filter is much more effective at removing impulse noise, also known as salt and pepper noise, than traditional median filter.
Adaptive local noise reduction filters are useful for processing images that have too much noise to deal with with other simpler filters.
Alpha trimmed mean filter is a combination of mean filters and order-statistic filters. This guide shows how to use them with C#.
Midpoint filter is a order-statistic filter and we use it to process image data in spatial domain. This guide shows how to make it with C#.
Color histogram equalization is an image processing technique for color images. If you’re familiar with this blog, you might be aware that we’ve already described a version of it, one we used on grayscale images.
In any case, if you’re not familiar, histogram equalization methods enable us to adjust contrast on an image. Furthermore, contrast is the difference between features that make an object stand out from other objects in the background.
Problem we’re tackling here is how can we optimize the contrast, so we can see all the information in the image.
There are also several techniques that deal with this problem. The most common few are histogram equalization, gamma correction and linear contrast correction.
As we mentioned before, we used histogram equalization technique before, where we processed a grayscale image. However, when we’re dealing with grayscale images, we only need to equalize image data in one channel.
So here, we bump into another obstacle, which is processing image data across three color channels. Therefore, we’ll talk about a couple different methods of equalizing a color image.
For a simple solution to our problem, we could just equalize each color channel sub-image separately and put it back together. However, this method usually produces an image with erroneous color.
Another method we could use, starts by converting an image from RGB to HSI color space. This way, we separate all color carrying information from their intensities. Therefore, we can equalize intensity sub-image and put it all back together and convert the image back to RGB color space.
Histogram equalization process that we described in another guide is only effective for equalizing images in separate color channels. However, in this tutorial we’ll be using an iterative equalization of the image by using nth root or power.
public static Bitmap EqualizeHistogram(this double[][] hsi)
{
double[] intensities = hsi[2];
//normalize
double max = 0d;
for (int i = 0; i < intensities.Length; i++)
{
max = Math.Max(max, intensities[i]);
}
for (int i = 0; i < intensities.Length; i++)
{
intensities[i] /= max;
}
//calculate new intensities
double mean = 0d;
while (Math.Round(mean, 2) != 0.5)
{
mean = intensities.Sum() / intensities.Length;
double theta = Math.Log(0.5) / Math.Log(mean);
for (int i = 0; i < intensities.Length; i++)
{
intensities[i] = Math.Pow(intensities[i], theta);
}
}
//normalize to range
double min = 255d;
max = 0d;
for (int i = 0; i < intensities.Length; i++)
{
min = Math.Min(min, intensities[i]);
max = Math.Max(max, intensities[i]);
}
for (int i = 0; i < intensities.Length; i++)
{
intensities[i] = 255 * (intensities[i] - min) / (max - min);
}
//make new image
double[][] result = { hsi[0], hsi[1], intensities };
Bitmap res_img = result.HSI2RGB();
return res_img;
}
This guide expands on the previous post about histogram equalization by adding a new technique. I hope it was helpful.
You can also download the project and try it out yourself.