This might be helpful to you
public static Bitmap ImageSharpen(Bitmap InpImg)
{
Bitmap sharpenImage = new Bitmap(InpImg.Width, InpImg.Height);
int wdth = InpImg.Width;
int hght = InpImg.Height;
double[,] filter = new double[3, 3];
filter[0, 0] = filter[0, 1] = filter[0, 2] = filter[1, 0] = filter[1, 2] = filter[2, 0] = filter[2, 1] = filter[2, 2] = -1;
filter[1, 1] = 9;
double factor = 1.0;
double bias = 0.0;
Color[,] result = new Color[InpImg.Width, InpImg.Height];
for (int x = 0; x < wdth; ++x)
{
for (int y = 0; y < hght; ++y)
{
double red = 0.0, green = 0.0, blue = 0.0;
Color imageColor = InpImg.GetPixel(x, y);
for (int filterX = 0; filterX < 3; filterX++)
{
for (int filterY = 0; filterY < 3; filterY++)
{
int imageX = (x - 3 / 2 + filterX + wdth) % wdth;
int imageY = (y - 3 / 2 + filterY + hght) % hght;
Color imageColor = InpImg.GetPixel(imageX, imageY);
red += imageColor.R * filter[filterX, filterY];
green += imageColor.G * filter[filterX, filterY];
blue += imageColor.B * filter[filterX, filterY];
}
int r = Math.Min(Math.Max((int)(factor * red + bias), 0), 255);
int g = Math.Min(Math.Max((int)(factor * green + bias), 0), 255);
int b = Math.Min(Math.Max((int)(factor * blue + bias), 0), 255);
result[x, y] = Color.FromArgb(r, g, b);
}
}
}
for (int i = 0; i < wdth; ++i)
{
for (int j = 0; j < hght; ++j)
{
sharpenImage.SetPixel(i, j, result[i, j]);
}
}
return sharpenImage;
}