写了一个过程,在D6下通过.
希望不是50分,而且300分.
var
Bmp, Bound: TBitmap;
p1, p2, p3, pr: PByteArray;
i, j, b: Integer;
begin
Bmp := TBitmap.Create;
Bound := TBitmap.Create;
try
//载入二值图
Bmp.LoadFromFile(InFileName);
Bmp.PixelFormat := pf8Bit;
//初始化边界图
Bound.Assign(Bmp);
with Bound.Canvas do begin
Brush.Color := clBlack;
FillRect(Rect(0, 0, Bound.Width, Bound.Height));
end;
//边界查找
p2 := Bmp.ScanLine[0];
p3 := Bmp.ScanLine[1];
for i := 1 to Bmp.Height - 2 do begin
p1 := p2;
p2 := p3;
p3 := Bmp.ScanLine[i + 1];
pr := Bound.ScanLine;
for j := 1 to Bmp.Width - 2 do begin
b := p2[j] * 20
- (p1[j - 1] + p1[j + 1] + p3[j - 1] + p3[j + 1])
- (p1[j] + p2[j - 1] + p2[j + 1] + p3[j]) * 4;
if b > 255 then pr[j] := 255;
end;
end;
//保存边界结果
Bound.SaveToFile(OutFileName);
finally
Bound.Free;
Bmp.Free;
end;
end;