var
bmp: Tbitmap;
i, j, S, Vx , Vy: Integer;
o, t, c, b: pRGBTripleArray;
nb: array[1..3, 1..3] of Integer;
ncount: integer;
begin
bmp := tbitmap.Create;
bmp.Width := image.Width;
bmp.Height := image.Height;
bmp.Assign(image.Picture.Bitmap);
for i := 1 to bmp.Height - 2 do
begin
o := image.Picture.Bitmap.ScanLine;
t := bmp.ScanLine[i - 1];
c := bmp.ScanLine;
b := bmp.ScanLine[i + 1];
for j := 1 to bmp.width - 2 do
begin
nb[1, 1] := t[j - 1].rgbtRed div 255;
nb[1, 2] := t[j].rgbtRed div 255;
nb[1, 3] := t[j + 1].rgbtRed div 255;
nb[2, 1] := c[j - 1].rgbtRed div 255;
nb[2, 2] := c[j].rgbtRed div 255;
nb[2, 3] := c[j + 1].rgbtRed div 255;
nb[3, 1] := b[j - 1].rgbtRed div 255;
nb[3, 2] := b[j].rgbtRed div 255;
nb[3, 3] := b[j + 1].rgbtRed div 255;
//--------Sobel算子 ,边缘可能不止一个像素?
Vx := (nb[1,1] + 2 * nb[1,2] + nb[1,3]) - (nb[3,1] + 2 * nb[3,2] + nb[3,3]);
Vy := (nb[1,1] + 2 * nb[2,1] + nb[3,1]) - (nb[1,3] + 2 * nb[2,3] + nb[3,3]);
if (abs(Vx) + abs(Vy)) = 0 then // nb[2,2]不是边缘 //这里的判断条件,abs(Vx) + abs(Vy)) = 0 不知
// 道对不对,请其他人回答一下
begin
o[j].rgbtRed := 255;
o[j].rgbtGreen := 255;
o[j].rgbtBlue := 255;
end;
end;
end;
bmp.Free;
Image.Refresh;
end;