procedure TMainForm.normalsharpClick(Sender: TObject);//标准模板
var
bmp1, bmp2: Tbitmap;
p1, p2, p3, p4: pbytearray;
i, j: integer;
begin
self.DoubleBuffered := true;
bmp1 := Tbitmap.Create;
bmp2 := Tbitmap.Create;
bmp1.Assign(ChildForm.image1.Picture.Bitmap);
bmp1.PixelFormat := pf24bit;
bmp1.Width := ChildForm.image1.Picture.Graphic.Width;
bmp1.Height := ChildForm.image1.Picture.Graphic.Height;
bmp2.Assign(ChildForm.image1.Picture.Bitmap);
bmp2.PixelFormat := pf24bit;
starttime := GetTickCount;
for j := 1 to bmp1.Height - 2 do
begin
p1 := bmp1.ScanLine[j];
p2 := bmp2.ScanLine[j - 1];
p3 := bmp2.ScanLine[j];
p4 := bmp2.ScanLine[j + 1];
for i := 1 to bmp1.Width - 2 do
begin
p1[3 * i + 2] := min(255, max(0, ((-p2[3 * (i - 1) + 2] - p2[3 * i
+ 2] -
p2[3 * (i + 1) + 2] - p3[3 * (i - 1) + 2] + 16 * p3[3 * i +
2]
- p3[3 *
(i
+ 1) + 2] - p4[3 * (i - 1) + 2] - p4[3 * i + 2] - p4[3 * (i
+ 1) + 2])
div
8)));
p1[3 * i + 1] := min(255, max(0, ((-p2[3 * (i - 1) + 1] - p2[3 * i
+ 1] -
p2[3 * (i + 1) + 1] - p3[3 * (i - 1) + 1] + 16 * p3[3 * i +
1]
- p3[3 *
(i
+ 1) + 1] - p4[3 * (i - 1) + 1] - p4[3 * i + 1] - p4[3 * (i
+ 1) + 1])
div
8)));
p1[3 * i] := min(255, max(0, ((-p2[3 * (i - 1)] - p2[3 * i] - p2[3
* (i +
1)] - p3[3 * (i - 1)] + 16 * p3[3 * i] - p3[3 * (i + 1)] -
p4[3 * (i -
1)]
- p4[3 * i] - p4[3 * (i + 1)]) div 8)));
end;
end;
ChildForm.Image1.Picture.Bitmap.Assign(Bmp1);
bmp1.free;
bmp2.free;
end;
以上是24位图的锐化,模板就是p[2*x+1],p[2*x+2],p[2*x]前面的系数
8位的自己改一下!那就是对p[x]操作了,更简单!