(b)
Gambar Ilustrasi deteksi batas (a) citra awal, (b) citra hasil deteksi batas.Berikut adalah Sintaks Deteksi Batas dengan Delphi
procedure Tform1.DeteksiBatas(Image:TBitmap);
var
x,y:Integer;
Arr:array of Boolean;
Temp,Max,TempStart,Start,TempFinish, Tempo:Integer;
begin
SetLength(Arr,Image.Height);
for y:=0 to Image.Height-1 do
begin
Arr[y]:=False;
for x:=0 to Image.Width-1 do
if Image.Canvas.Pixels[x,y]<>$ffffff then
begin
Arr[y]:=True;
end;
end;
Max:=0;
Temp:=0;
Tempo:=0;
for y:=0 to Length(Arr)-1 do
begin
if Arr[y] then
begin
if Tempo=0 then
begin
TempStart:=y;
end else
if Temp>Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=y;
end else if Temp=Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=y;
end;
inc(Tempo);
end;
inc(Temp);
end;
Temp:=TempFinish-TempStart;
Image.Canvas.Draw(0,-start,Image);
Image.Height:=Temp+1;
SetLength(Arr,Image.Width);
for x:=0 to Length(Arr)-1 do
begin
Arr[x]:=False;
for y:=0 to Image.Height-1 do if Image.Canvas.Pixels[x,y]<>$FFFFFF then
begin
Arr[x]:=True;
end;
end;
Max:=0;
Temp:=0;
Tempo:=0;
for x:=0 to Length(Arr)-1 do
begin
if Arr[x] then
begin
if Tempo=0 then
begin
TempStart:=x;
end else
if Temp>Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=x;
end else if Temp=Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=x;
end;
inc(Tempo);
end;
inc(Temp);
end;
Temp:=TempFinish-TempStart;
Image.Canvas.Draw(-Start,0,Image);
Image.Width:=Temp+1;
end;
Tidak ada komentar:
Posting Komentar