0% found this document useful (0 votes)
178 views

Source Code Delphi

The document defines a unit called UnitUtama that contains the declaration of a form class called TFormUtama. The form class contains various buttons, labels, and other controls. It also defines procedures to handle button click events that perform image processing tasks like loading an image, segmentation, edge detection, inverting to black/white, and saving the processed image.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views

Source Code Delphi

The document defines a unit called UnitUtama that contains the declaration of a form class called TFormUtama. The form class contains various buttons, labels, and other controls. It also defines procedures to handle button click events that perform image processing tasks like loading an image, segmentation, edge detection, inverting to black/white, and saving the processed image.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

unit UnitUtama; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtDlgs, Menus,

StdCtrls, ComCtrls, Clipbrd, ExtCtrls, TeeProcs, TeEngine, Chart, Series, CPort; type TFormUtama = class(TForm) PanelAtas: TPanel; ButtonAmbilCitra: TButton; StatusBar: TStatusBar; OpenPictureDialog: TOpenPictureDialog; ButtonSegmentasi: TButton; ButtonDeteksiTepi: TButton; ButtonHitam: TButton; ButtonPutih: TButton; ButtonReset: TButton; ButtonSave: TButton; ButtonClose: TButton; Shape1: TShape; Shape2: TShape; Memo1: TMemo; SaveDialog1: TSaveDialog; SavePictureDialog1: TSavePictureDialog; ComPort1: TComPort; Edit1: TEdit;

Button1: TButton; Edit2: TEdit; Button2: TButton; ButtonPrint: TButton; Label1: TLabel; Label3: TLabel; Label2: TLabel; Label4: TLabel; procedure ButtonAmbilCitraClick(Sender: TObject); procedure Segmentasi; procedure DeteksiTepi; procedure ButtonSegmentasiClick(Sender: TObject); procedure ButtonDeteksiTepiClick(Sender: TObject); procedure ButtonCloseClick(Sender: TObject); procedure ButtonSaveClick(Sender: TObject); procedure ButtonHitamClick(Sender: TObject); procedure ButtonPutihClick(Sender: TObject); procedure ComPort1RxChar(Sender: TObject; Count: Integer); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Button2Click(Sender: TObject); procedure ButtonPrintClick(Sender: TObject); private { Private declarations } public

{ Public declarations } end; var FormUtama: TFormUtama; implementation uses UnitCitra; var FormHasil: TFormCitra; xx, yy, C , R, G, B, ii, jj, brs, klm : Integer; terimaserial: string; urutan : integer; {$R *.dfm} procedure TFormUtama.ButtonAmbilCitraClick(Sender: TObject); var fc: string; begin if (OpenPictureDialog.Execute) then begin if (FormCitra = nil) then Application.CreateForm(TFormCitra, FormCitra); FormCitra.Image.Picture.LoadFromFile( OpenPictureDialog.FileName);

pf1bit : fc := 'biner'; pf8bit : fc := 'keabuan'; pf24bit : fc := 'true color'; end; StatusBar.SimpleText := OpenPictureDialog.FileName + ' (' + IntToStr(FormCitra.Image.Picture.Width) + 'x' + IntToStr(FormCitra.Image.Picture.Height) + ', ' + fc + ')'; if (FormHasil = nil) then Application.CreateForm(TFormCitra, FormHasil); FormHasil.Caption := 'Citra Hasil'; FormHasil.Image.Picture := FormCitra.Image.Picture; FormHasil.Top := FormCitra.Top; FormHasil.Left := FormCitra.Left; FormHasil.ClientHeight := FormHasil.Image.Picture.Height; FormHasil.ClientWidth := FormHasil.Image.Picture.Width; FormHasil.ClientHeight := FormHasil.Image.Picture.Height; end; end; procedure TFormUtama.Segmentasi; begin for xx:=1 to FormCitra.Image.Picture.Width do

FormCitra.ClientHeight :=FormCitra.Image.Picture.Height; for yy:=1 to FormCitra.Image.Picture.Height do FormCitra.ClientWidth :=FormCitra.Image.Picture.Width; FormCitra.ClientHeight := FormCitra.Image.Picture.Height; case (FormCitra.Image.Picture.Bitmap.PixelFormat) of begin C:=FormCitra.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]; R:= C mod $100; G:= (C div $100)mod $100;

B:= C div $10000; R:= ((r*4) div 256) *(255 div (3)); G:= ((g*4) div 256) *(255 div (3)); B:= ((b*4) div 256) *(255 div (3));

begin if (FormCitra = nil) then begin ShowMessage('Ambil dulu citra yang akan diolah');

FormCitra.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]:=B*$1 exit; 0000+G*$100+R; end;

FormHasil.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]:=B*$1 Segmentasi; 0000+G*$100+R; end; end; procedure TFormUtama.DeteksiTepi; Begin for xx:=0 to FormHasil.Image.Picture.Bitmap.Width do for yy:=0 to FormHasil.Image.Picture.Bitmap.Height do begin C:= FormCitra.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]; end; procedure TFormUtama.ButtonDeteksiTepiClick(Sender: TObject); begin if (FormCitra = nil) then begin ShowMessage('Ambil dulu citra yang akan diolah'); exit; end;

FormHasil.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]:=clWh Segmentasi; ite; for ii:=-1 to +1 do for jj:=-1 to +1 do if C<>FormCitra.Image.Picture.Bitmap.Canvas.Pixels [xx+ii,yy+jj] then FormHasil.Image.Picture.Bitmap.Canvas. Pixels [xx,yy]:=clBlack; end; end; procedure TFormUtama.ButtonSegmentasiClick(Sender: TObject); DeteksiTepi; end; procedure TFormUtama.ButtonHitamClick(Sender: TObject); begin if (FormCitra = nil) then begin ShowMessage('Ambil dulu citra yang akan diolah'); exit; end;

for brs:=0 to FormCitra.Image.Picture.Bitmap.Width do for klm:=0 to FormCitra.Image.Picture.Bitmap.height do begin if

end; end; procedure TFormUtama.ButtonSaveClick(Sender: TObject); begin

FormCitra.Image.Picture.Bitmap.Canvas.Pixels[brs,klm]=Sha if (FormCitra = nil) then pe2.Brush.Color then begin ShowMessage('Ambil dulu citra yang akan diolah');

FormHasil.Image.Picture.Bitmap.Canvas.Pixels[brs,klm]:=clB exit; lack; end; end; end; if SavePictureDialog1.Execute then FormHasil.Image.Picture.SaveToFile(SavePictureDialog1.File

procedure TFormUtama.ButtonPutihClick(Sender: TObject); Name); begin if (FormCitra = nil) then begin ShowMessage('Ambil dulu citra yang akan diolah'); exit; end; for brs:=0 to FormCitra.Image.Picture.Bitmap.Width do for klm:=0 to FormCitra.Image.Picture.Bitmap.height do begin if end; procedure TFormUtama.ButtonCloseClick(Sender: TObject); begin Close; end; procedure TFormUtama.ComPort1RxChar(Sender: TObject; Count: Integer); Var dataterima: String; begin Comport1.ReadStr(dataterima,count);

FormCitra.Image.Picture.Bitmap.Canvas.Pixels[brs,klm]=Sha terimaserial := terimaserial+dataterima; pe1.Brush.Color then if pos(#13+#10,terimaserial)> 0 then begin

FormHasil.Image.Picture.Bitmap.Canvas.Pixels[brs,klm]:=cl edit1.Text:= terimaserial; White; terimaserial := '';

end; end; procedure TFormUtama.FormCreate(Sender: TObject); begin terimaserial :=''; end; procedure TFormUtama.Button1Click(Sender: TObject); begin Comport1.WriteStr(Memo1.Lines.Strings[0]+'00'+ #13); urutan := 0; FormUtama.Caption:= Timetostr(now); end; procedure TFormUtama.Edit1Change(Sender: TObject); begin if pos('-OK', edit1.Text) > 0 then begin urutan := urutan+1; comport1.WriteStr(memo1.Lines.Strings[urutan]+'00'+ #13); Label1.Caption:=timetostr(now); end; end; procedure TFormUtama.Button2Click(Sender: TObject); begin Comport1.WriteStr(edit2.text + #13); end; procedure TFormUtama.ButtonPrintClick(Sender: TObject);

var xx,yy,warnaawal,putih,hitam: integer; ADAHITAM:BOOLEAN; begin memo1.Text:=''; YY:=0; REPEAT hitam:=0; putih:=0; warnaawal:=FormHasil.Image.Picture.Bitmap.Canvas.Pixels[ 00,yy]; ADAHITAM:=FALSE; for xx:=0 to FormHasil.Image.Picture.Bitmap.Width-1 do begin if FormHasil.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]=clblac k then ADAHITAM:=TRUE; END; IF ADAHITAM THEN BEGIN hitam:=0; putih:=0; warnaawal:=FormHasil.Image.Picture.Bitmap.Canvas.Pixels[ 00,yy]; for xx:=0 to FormHasil.Image.Picture.Bitmap.Width-1 do begin

if

memo1.Lines.Append('E10') ;

FormHasil.Image.Picture.Bitmap.Canvas.Pixels[xx,yy]=clblac end k then begin if warnaawal<>clBlack then memo1.Lines.Append('A'+inttostr(putih)); putih:=0; hitam:=hitam+1; warnaawal:=clBlack; end else begin if warnaawal<>clwhite then begin memo1.Lines.Append('F10') ; memo1.Lines.Append('A'+inttostr(hitam)) ; memo1.Lines.Append('E10') ; end; hitam:=0; putih:=putih+1; warnaawal:=clwhite; end; end; if warnaawal<>clwhite then begin memo1.Lines.Append('F10') ; memo1.Lines.Append('A'+inttostr(hitam)) ; else memo1.Lines.Append('A'+inttostr(putih)); memo1.Lines.Append('C1'); END ELSE BEGIN MEMO1.Lines.Add('C1'); END; YY:=YY+1; UNTIL YY=FormHasil.Image.Picture.Bitmap.Height-1 end; end.

You might also like