public Bitmap GammaCorrection(Bitmap OriginalImage, Double Gamma)
{
Bitmap OutputImage = new System.Drawing.Bitmap(OriginalImage.Width, OriginalImage.Height);
for (int x = 0; x < OriginalImage.Width; x++)
{
for (int y = 0; y < OriginalImage.Height; y++)
{
Color pixel = OriginalImage.GetPixel(x, y);
int red = (int)(255 * Math.Pow(Convert.ToDouble(pixel.R) / 255, Gamma));
int green = (int)(255 * Math.Pow(Convert.ToDouble(pixel.G) / 255, Gamma));
int blue = (int)(255 * Math.Pow(Convert.ToDouble(pixel.B) / 255, Gamma));
if (red > 255) red = 255;
if (red < 0) red = 0;
if (green > 255) green = 255;
if (green < 0) green = 0;
if (blue > 255) blue = 255;
if (blue < 0) blue = 0;
Color newColor = Color.FromArgb(255, red, green, blue); ;
OutputImage.SetPixel(x, y, newColor);
}
}
return OutputImage;
}