You are on page 1of 4

NIM : 20190810026

Nama : Putri Yusinta Paudilah


Kelas : TI2019B
Matkul : Pengolahan Citra

Tampilan form

Script
unit UnitSobel;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, jpeg;

type
TForm1 = class(TForm)
Label1: TLabel;
Image1: TImage;
btOpen: TButton;
btSobel: TButton;
btKeluar: TButton;
Image2: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure btOpenClick(Sender: TObject);
procedure btSobelClick(Sender: TObject);
procedure btKeluarClick(Sender: TObject);
private
{ Private declarations }
procedure Sobel;
public
{ Public declarations }
end;
var
Form1: TForm1;
FileNameImg: string;
implementation
{$R *.dfm}

procedure TForm1.btOpenClick(Sender: TObject);


begin
if OpenPictureDialog1.Execute then
begin
FileNameImg := OpenPictureDialog1.FileName;
Caption := 'Deteksi Tepi Sobel : '+ OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile (OpenPictureDialog1.FileName);
Image2.Visible := False;
end;
end;
procedure TForm1.btSobelClick(Sender: TObject);
begin
Image2.Visible := True;
Image2.Picture.Graphic := Image1.Picture.Graphic;
Sobel;
end;
procedure TForm1.Sobel;
const sobel : array[0..1,0..2,0..2] of smallint =
(((-1,0,1),(-2,0,2),(-1,0,1)),((-1,-2,-1),(0,0,0),(1,2,1)));
prewitt : array[0..1,0..2,0..2] of smallint =
(((-1,0,1),(-1,0,1),(-1,0,1)),((-1,-1,-1),(0,0,0),(1,1,1)));
var
row:array[0..8] of pbytearray;
col:pbytearray;
x,y:smallint;
i,j,k,p:smallint;
image:tbitmap;
sum,jum:longint;
begin
p:=-120;
image:=Tbitmap.Create;
image.Assign(Image1.Picture.Bitmap);
for y:=1 to Image1.Height-2 do
begin
for i:=-1 to 1 do
row[i+1]:= image.ScanLine[y+i];
col:=Image1.Picture.Bitmap.ScanLine[y];
x:=3;
repeat
sum:=0;
for i:=-1 to 1 do
for j:=-1 to 1 do
sum:=sum+(sobel[0,i+1,j+1]*row[i+1,x+j*3]);
jum:=0;
for i:=-1 to 1 do
for j:=-1 to 1 do
jum:=jum+(sobel[1,i+1,j+1]*row[i+1,x+j*3]);
sum:=(sum+jum)+p;
if sum>255 then sum:=255;
if sum<0 then sum:=0;
for k:=0 to 2 do col[x+k]:=sum;
inc(x,3);
until x>=3*(Image1.Width-4);
end;
Image2.picture.bitmap:=Image1.Picture.Bitmap;
image.free;
end;
procedure TForm1.btKeluarClick(Sender: TObject);
begin
Form1.Close;
end;
end.

Output

You might also like