Sunteți pe pagina 1din 3

unit UnitUtama;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtDlgs, Menus, StdCtrls, ComCtrls, Clipbrd, ExtCtrls, Spin;

type TFormUtama = class(TForm) PanelAtas: TPanel; ButtonAmbilCitra: TButton; StatusBar: TStatusBar; OpenPictureDialog: TOpenPictureDialog; ButtonAmbilCitra2: TButton; ButtonDeteksiGerak: TButton; SpinEditC: TSpinEdit; Label1: TLabel; procedure ButtonAmbilCitraClick(Sender: TObject); procedure ButtonAmbilCitra2Click(Sender: TObject); procedure Olah;

procedure ButtonDeteksiGerakClick(Sender: TObject); private

{ Private declarations } public

{ Public declarations }

end;

var FormUtama: TFormUtama;

implementation

uses UnitCitra;

var FormCitra2, FormHasil: TFormCitra;

{$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); FormCitra.ClientHeight := FormCitra.Image.Picture.Height; FormCitra.ClientWidth := FormCitra.Image.Picture.Width; FormCitra.ClientHeight := FormCitra.Image.Picture.Height; case (FormCitra.Image.Picture.Bitmap.PixelFormat) of 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 + ')';

end;

end;

procedure TFormUtama.ButtonAmbilCitra2Click(Sender: TObject); begin if (FormCitra = nil) then begin ShowMessage('Ambil citra pertama dulu'); exit; end; if (OpenPictureDialog.Execute) then begin if (FormCitra2 = nil) then Application.CreateForm(TFormCitra, FormCitra2);

FormCitra2.Image.Picture.LoadFromFile(

OpenPictureDialog.FileName); FormCitra2.ClientHeight :=

FormCitra2.Image.Picture.Height;

FormCitra2.ClientWidth :=

FormCitra2.Image.Picture.Width;

FormCitra2.ClientHeight :=

FormCitra2.Image.Picture.Height;

FormCitra2.Caption := 'Citra 2'; FormCitra2.Top := FormCitra.Top; FormCitra2.Left := FormCitra.Left+FormCitra.Width; end;

end;

procedure TFormUtama.Olah; var i, j, C, temp: integer; PC, PC2, PH: PByteArray; begin C := SpinEditC.Value; if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf8bit) then begin for i:= 0 to FormCitra.Image.Picture.Height-1 do begin PC := FormCitra.Image.Picture.BitMap.ScanLine[i]; PC2 := FormCitra2.Image.Picture.BitMap.ScanLine[i]; PH := FormHasil.Image.Picture.BitMap.ScanLine[i]; for j:= 0 to FormCitra.Image.Picture.Width-1 do begin temp := C+PC[j]-PC2[j]; if (temp < 0) then temp := 0; if (temp > 255) then temp := 255; PH[j] := temp; end;

end;

end; if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf24bit) then begin for i:= 0 to FormCitra.Image.Picture.Height-1 do begin PC := FormCitra.Image.Picture.BitMap.ScanLine[i]; PC2 := FormCitra2.Image.Picture.BitMap.ScanLine[i]; PH := FormHasil.Image.Picture.BitMap.ScanLine[i]; for j:= 0 to FormCitra.Image.Picture.Width-1 do begin temp := C+PC[3*j]-PC2[3*j]; if (temp < 0) then temp := 0; if (temp > 255) then temp := 255; PH[3*j] := temp; temp := C+PC[3*j+1]-PC2[3*j+1]; if (temp < 0) then temp := 0;

if (temp > 255) then temp := 255; PH[3*j+1] := temp; temp := C+PC[3*j+2]-PC2[3*j+2]; if (temp < 0) then temp := 0; if (temp > 255) then temp := 255; PH[3*j+2] := temp; end

end;

end;

end;

procedure TFormUtama.ButtonDeteksiGerakClick(Sender: TObject); begin if (FormCitra2 = nil) then begin ShowMessage('Ambil citra pertama dulu'); exit; end; if (FormHasil = nil) then Application.CreateForm(TFormCitra, FormHasil); FormHasil.Caption := 'Citra Hasil'; FormHasil.Image.Picture := FormCitra.Image.Picture; FormHasil.ClientHeight := FormHasil.Image.Picture.Height; FormHasil.ClientWidth := FormHasil.Image.Picture.Width; FormHasil.ClientHeight := FormHasil.Image.Picture.Height; FormHasil.Top := FormCitra2.Top; FormHasil.Left := FormCitra2.Left+FormCitra.Width; Olah; end;

end.