高斯模糊算法可以借鉴一下,用的是scanline,即某个点的新的象素值是周围的8个象素点的
平均,你的那个灰度也是一样的,适合于24bit
procedure TMainForm.GaotemplateClick(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;
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] := (p2[3 * (i - 1) + 2] + 2 * p2[3 * i + 2] +
p2[3
* (i + 1)
+ 2] + 2 * p3[3 * (i - 1) + 2] + 4 * p3[3 * i + 2] + 2
*
p3[3
* (i + 1)
+
2] + p4[3 * (i - 1) + 2] + 2 * p4[3 * i + 2] + p4[3 *
(i +
1) + 2])
shr
4;
p1[3 * i + 1] := (p2[3 * (i - 1) + 1] + 2 * p2[3 * i + 1] +
p2[3
* (i + 1)
+ 1] + 2 * p3[3 * (i - 1) + 1] + 4 * p3[3 * i + 1] + 2
*
p3[3
* (i + 1)
+
1] + p4[3 * (i - 1) + 1] + 2 * p4[3 * i + 1] + p4[3 *
(i +
1) + 1])
shr
4;
p1[3 * i] := (p2[3 * (i - 1)] + 2 * p2[3 * i] + p2[3 * (i +
1)] +
2 * p3[3
* (i - 1)] + 4 * p3[3 * i] + 2 * p3[3 * (i + 1)] + p4[3 *
(i -
1)] + 2 *
p4[3 * i] + p4[3 * (i + 1)]) shr 4;
end;
end;
bmp1.free;
bmp2.free;