}
else
{
MessageBox.Show("请先打开一张图片!");
}
}
三、锐化
突出显示颜色值大的像素点。
/// <summary>
/// 锐化实现方法,显示数值最大像素点
/// </summary>
void Image_Sharpen()
{
if (this.pbshowbox.Image != null)
{
int Height = this.pbshowbox.Image.Height;
int Width = this.pbshowbox.Image.Width;
Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppRgb);
Bitmap MyBitmap = (Bitmap)this.pbshowbox.Image;
BitmapData oldData = MyBitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
unsafe
{
byte* pin = (byte*)(oldData.Scan0.ToPointer());
byte* pout = (byte*)(newData.Scan0.ToPointer());
//拉普拉斯模板
int[] Laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };
for (int i = 1; i < Width - 1; i++)
{
for (int j = 1; j < Height - 1; j++)
{
int r = 0, g = 0, b = 0;
int Index = 0;
for (int col = -1; col <= 1; col++)
{
for (int row = -1; row <= 1; row++)
{
int off = ((j + row) * (Width) + (i + col)) * 4;
r += pin[off + 0] * Laplacian[Index];
g += pin[off + 1] * Laplacian[Index];
b += pin[off + 2] * Laplacian[Index];
Index++;
}
}