• Tidak ada hasil yang ditemukan

4. IMPLEMENTASI SISTEM

N/A
N/A
Protected

Academic year: 2022

Membagikan "4. IMPLEMENTASI SISTEM"

Copied!
25
0
0

Teks penuh

(1)

4. IMPLEMENTASI SISTEM

Berdasarkan rancangan sistem yang telah dibahas pada bab sebelumnya, berikut ini adalah hasil implementasi sistem aplikasi morphing. Implementasi sistem aplikasi morphing menggunakan 2 buah form sebagai form utama dan beberapa procedure yang digunakan untuk melakukan image morphing.

4.1 Implementasi Software yang Digunakan

Software yang digunakan untuk implementasi program morphing adalah Borland Delphi 7. Alasan penggunaan Borland Delphi 7 adalah karena delphi mendukung proses imaging, bersifat user friendly, dan mempunyai interface yang dapat didesain dan diatur dengan baik sehingga siap untuk digunakan. Selain itu, delphi 7 mempunyai performa yang cukup cepat dalam melakukan perhitungan yang banyak.

Pada Delphi 7 memori komputer yang digunakan untuk penyimpanan suatu obyek maupun untuk menjalankan proses, menyimpan variabel temporary mempunyai kualitas yang cukup besar. Dengan menggunakan delphi 7, maka pembuatan class sendiri tidak diperlukan dikarenakan bahasa pemrograman delphi 7 sudah menerapkan pemrograman berorientasi obyek.

4.2. Implementasi Software yang Dibuat

4.2.1. Library dan Unit yang Digunakan

Library dan Unit menggunakan standar dari Delphi ditambah dengan unit JPEG, GIFImage, dan AVIWriter. Unit JPEG digunakan untuk membuka file image yang ber-format JPEG, GIFImage digunakan untuk menghasilkan image bergerak yang ber-format GIF, sedangkan AVIWriter digunakan untuk menghasilkan sebuah Movie yang ber-format AVI. Daftar library dan unit yang digunakan selengkapnya pada Segmen Program 4.1.

Segmen Program 4.1. Library dan Unit

(2)

Uses

GIFImage,

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs,JPEG, StdCtrls, Buttons, ExtCtrls, ExtDlgs,Math, ComCtrls, Menus,

AviWriter_2;

4.2.2. Header Procedure dan Function

Header procedure dan function yang terdapat pada Segmen Program 4.2.

merupakan header procedure dan function yang digunakan pada aplikasi morphing. Aplikasi morphing ini tidak hanya menggunakan procedure dan function seperti yang terdapat pada Segmen Program 4.2, melainkan procedure dan function lain yang sifatnya lebih umum.

Segmen Program 4.2. Header Procedure dan Function utama.

procedure JPEGtoBMP(file_name:string);

function copynamafile(file_name:string) : string;

procedure cekJPEGBMP();

procedure interpolasi(image : TImage; w,h,w1,h1 : integer);

procedure dt_source(jumframe : integer; image : TImage);

procedure dt_dest(jumframe : integer; image : TImage);

procedure ubah_dest(jumframe : integer; image : TImage);

procedure ubah_source(jumframe : integer; image : TImage);

procedure crossdissolve(img1,img2:timage;jumframe:integer);

procedure Open_source(imagename : string);

procedure Open_dest(imagename : string);

function panjangvector(x1,y1,x2,y2 : real) : real;

function carif(x,y : real; grs : TgrsFeature):real;

function carid1(x,y : real; grs : TgrsFeature):real;

procedure interpolasihasil();

4.2.3. Form Aplikasi Morphing

Aplikasi ini mempunyai 1 form utama dengan 2 form tambahan untuk

video dan hasil video. Form utama digunakan untuk proses image morphing yang

terdiri dari image source dan image destination. Dalam form utama juga dapat

dilihat hasil morphing yang terjadi. Tampilan dari form utama dapat dilihat pada

Gambar 4.1.

(3)

Gambar 4.1. Tampilan Form Utama Image Morphing

Form untuk video digunakan untuk melakukan morphing antara 2 buah file

AVI sehingga diperlukan beberapa tempat untuk melihat frame – frame yang ada

dalam sebuah file AVI, selain itu dibutuhkan juga tempat untuk memberikan garis

feature pada frame pertama dan frame akhir dari setiap file AVI. Tampilan

keseluruhan untuk form video morphing dapat dilihat pada gambar 4.2.

(4)

Gambar 4.2. Tampilan Form Video Morphing

4.2.4. Menu File

Pada menu file terdapat 5 fasilitas yang dapat digunakan oleh user. Menu yang ada digunakan untuk menciptakan suatu project dan mengakhiri suatu project. Pada Gambar 4.3. dapat dilihat item-item yang ada pada menu file. Menu file ada pada form movie dan image. Susunan menu file untuk kedua form sama agar memudahkan user untuk mengingat letak menu.

Gambar 4.3. Menu File

(5)

4.2.4.1. New Project Morphing

Menu File – New Project Morphing berfungsi untuk memanggil reset_morph untuk mengembalikan semua nilai menjadi nilai default awal.

Default awal adalah mengembalikan image source dan image destination menjadi kosong, selain itu, nilai garis feature juga harus dikembalikan menjadi -1.

Keseluruhan source code untuk melakukan reset dapat dilihat pada Segmen Program 4.3.

Segmen Program 4.3. Membuat Project Baru

1 procedure TImageMorphing.reset_morph();

2 var

3 i,j : integer;

4 begin

5 klik1 := false;

6 klik2 := false;

7 //--- 8 //untuk mereset jumlah garis Feature 9 for i:=1 to 100 do

10 begin

11 gf1[i].x_1:=-1;

12 gf1[i].x_2:=-1;

13 gf1[i].y_1:=-1;

14 gf1[i].y_2:=-1;

15

16 gf2[i].x_1:=-1;

17 gf2[i].x_2:=-1;

18 gf2[i].y_1:=-1;

19 gf2[i].y_2:=-1;

20 end;

21

22 for i:=0 to 1024 do 23 for j:=0 to 1024 do 24 begin

25 imageframe[i,j].R:=0;

26 imageframe[i,j].G:=0;

27 imageframe[i,j].B:=0;

28 imageframe[i,j].kode:=false;

29 end;

30

31 tamb := 1;

32 Timer1.Enabled := false;

33

34 //untuk garis Feature;

35 frame := 0;

36 jum_Feature:=1;

37 jum_point := 1;

38 imagehasil.Visible:=false;

(6)

Segmen Program 4.3. Membuat Project Baru (sambungan)

39 jalan := false;

40 label3.Caption:='000 / ';

41

42 //untuk button yang tidak dibuka dulu 43 play.Enabled:=false;

44 stop.Enabled:=false;

45

46 label1.Caption:='';

47 label2.Caption:='';

48

49 imagesource.Visible:=false;

50 imagedest.Visible:=false;

51

52 ListBox1.Selected[19]:= true;

53 listbox1.ItemIndex:=19;

54 jum_frame :=listbox1.ItemIndex+1;

55 end;

4.2.4.2. Open Project Morphing

Menu file-Open Project Morphing berfungsi untuk memanggil procedure open untuk membuka project yang sebelumnya pernah dibuat. Pada saat membuka Project maka file tersebut akan menganalisa satu per satu data yang disimpan. Dari data tersebut maka, variabel-variabel yang akan dipakai dalam proses morphing akan diberi nilai sesuai dengan yang ada pada data.

4.2.4.3. Open Image

Menu file-Open Image mempunyai sub menu lagi yaitu open image source dan open image destination. Open image source berfungsi untuk membuka image source yang ingin di-morphing, sedangkan open image destination berfungsi untuk membuka image destination yang ingin di-morphing. Sub menu yang ada pada menu open image dapat dilihat pada Gambar 4.4.

Gambar 4.4. SubMenu Open Image

Proses yang dilakukan oleh kedua menu tersebut pada dasarnya sama,

hanya saja temp yang digunakan untuk membuka image source dan image

(7)

destination berlainan. Temporary dari setiap image ini berfungsi agar setelah image di-morphing maka program masih menyimpan image yang asli seperti sebelumnya. Keseluruhan source code untuk membuka image dapat dilihat pada Segmen Program 4.4.

Segmen Program 4.4. Membuka Image

1 procedure TImageMorphing.Open_source(imagename : string);

2 begin

3 imagesource.Visible:=true;

4 imagesource.Picture.LoadFromFile(imagename);

5 Imagetempsource1.Picture.LoadFromFile(imagename);

6 Imagetempsource2.Picture.LoadFromFile(imagename);

7 Imagetempsource3.Picture.LoadFromFile(imagename);

8 files := copynamafile(imagename);

9 label1.Caption := imagename;

10 if label2.Caption<>'' then 11 begin

12 if (imagedest.Picture.Height<>imagesource.Picture.Height) 13 or (imagedest.Picture.Width<>imagesource.Picture.Width) 14 then

15 begin

16 PilImage.Visible := true;

17 showmessage('image source and destination not at the 18 same size '+#13+'Please Choose which image can resize');

18 end 19 else

20 Fieldmorph.Visible:=true;

21 end;

22 end;

4.2.4.4. Save Project

Menu File-Save Project berfungsi untuk memanggil procedure save

project. Procedure ini akan menyimpan semua data yang berkaitan dengan

perubahan image. Data-data yang perlu disimpan pada waktu sebuah project di-

save adalah titik-titik koordinat garis feature, jumlah garis feature dan image yang

digunakan untuk proses. Image yang digunakan untuk proses terdiri dari 2

macam, yaitu image source dan image destination Sebagian source code untuk

menyimpan project dapat dilihat pada Segmen Program 4.5.

(8)

Segmen Program 4.5. Menyimpan Project

1 filesave := saveproject.filename;

2 assignfile(fl,filesave);

3 rewrite(fl);

4 writeln(fl,label1.caption);

5 writeln(fl,label2.caption);

6 writeln(fl,inttostr(jum_frame));

7

8 if jum_Feature<>1 then 9 begin

10 writeln(fl,'fm');

11 writeln(fl,inttostr(jum_Feature));

12 end 13 else 14 begin

15 if jum_point<>1 then 16 begin

17 writeln(fl,'dt');

18 writeln(fl,inttostr(jum_point));

19 end 20 else

21 writeln(fl,'t');

22 end;

23

24 if (jum_Feature<>1) then 25 begin

26 for i:=1 to jum_Feature-1 do 27 begin

28 with gf1[i] do 29 begin

30 writeln(fl,floattostr(x_1)+';'

31 +floattostr(y_1)+';'+ (floattostr(x_2)) 32 +';'+floattostr(y_2));

33 end;

34 with gf2[i] do 35 begin

36 writeln(fl,floattostr(x_1)+';'

37 +floattostr(y_1)+';'+ (floattostr(x_2)) 38 +';'+floattostr(y_2));

39 end;

40 end;

41 end 42 else

43 if (jum_point<>1) then 44 begin

45 for i:=1 to jum_point-1 do 46 begin

47 writeln(fl,floattostr(pt1[i].x)+';' 48 +floattostr(pt1[i].y)+';');

49 writeln(fl,floattostr(pt2[i].x)+';' 50 +floattostr(pt2[i].y)+';');

51 end;

52 end;

53

54 closefile(fl);

(9)

4.2.4.5. Export

Menu File-Export berfungsi untuk menyimpan hasil morphing dengan format yang telah disediakan. Format file export yang disediakan dalam aplikasi ini adalah AVI dan GIF. Untuk menyimpan hasil image dalam bentuk AVI dan GIF, digunakan komponen tambahan. Proses penyimpanannya hampir sama dengan menyimpan setiap frame yang terjadi dalam sebuah file yang berformat AVI atau GIF. Tampilan submenu pada menu export dapat dilihat pada Gambar 4.5.

Gambar 4.5. SubMenu Export Hasil

4.2.5. Menu Morphing

Pada menu morphing terdapat 2 fasilitas yang dapat digunakan oleh user.

Submenu yang ada pada menu morphing berguna untuk membuat animasi dari dua buah gambar yang telah di-input-kan. Dalam menu morphing, user dapat memilih menggunakan metode Field Morphing ataupun deformation techniques.

Menu morphing ada pada form movie dan image. Pada Gambar 4.6. dapat dilihat item-item yang ada pada menu morphing

Gambar 4.6. Menu Morphing

4.2.5.1. Field Morphing

Menu field morphing berfungsi untuk menjalankan aplikasi dengan

metode field morphing. Pada metode field morphing digunakan beberapa image

(10)

temp yang sebelumnya telah diisi dengan image source dan image destination.

Pada field morphing maka image source dan destination, masing-masing akan mengalami deformasi. Setelah mengalami deformasi, maka kedua image akan digabungkan dengan menggunakan metode cross dissolve. Source code untuk metode field morphing dapat dilihat pada Segmen Program 4.6.

Segmen Program 4.6. Metode Field Morphing

1 procedure TImageMorphing.ubah_source 2 (jumframe : integer; image : TImage);

3 var

4 i,j,k,l,m : integer;

5 f,d,perb,f1,d1,grad : real;

6 x2,y2 : real;

7 hasilx,hasily : real;

8 xp,yp : real;

9 jrkttkfea : real;

10 jrkfea : real;

11 temp_f : TgrsFeature;

12

13 a,p,b : integer;

14 wght,wghtsum,DSUMx,DSUMy,dist,le,df,dxi,dyi : real;

15 hasilxf,hasilyf : real;

16 begin 17 m := 0;

18 l := 0;

19 f1:=0;

20

21 //untuk mengosongkan imageframe (Image yg terbentuk) 22 for i:=0 to imagetempsource1.Height-1 do

23 begin

24 f := carif(j,i,gf1[k]);

25 d := carid1(j,i,gf1[k]);

26

27 jrkfea := sqrt(sqr(gf1[k].x_2-gf1[k].x_1)+

28 (sqr(gf1[k].y_2-gf1[k].y_1)));

29 f := f/jrkfea;

30 perb := (1/(jumframe-1))*(frame);

31 //untuk menginisialisasi garis-garis yang baru timbul 32 antara hub antara source dan destination

33 temp_f.x_1:=gf1[k].x_1*(1-perb)+gf2[k].x_1*perb;

34 temp_f.y_1:=gf1[k].y_1*(1-perb)+gf2[k].y_1*perb;

35 temp_f.x_2:=gf1[k].x_2*(1-perb)+gf2[k].x_2*perb;

36 temp_f.y_2:=gf1[k].y_2*(1-perb)+gf2[k].y_2*perb;

(11)

Segmen Program 4.6. Metode Field Morphing (sambungan)

37 f := carif(j,i,gf1[k]);

38 d := carid1(j,i,gf1[k]);

39

40 jrkfea := sqrt(sqr(gf1[k].x_2-gf1[k].x_1)+

41 (sqr(gf1[k].y_2-gf1[k].y_1)));

42 f := f/jrkfea;

43 perb := (1/(jumframe-1))*(frame);

44 //untuk menginisialisasi garis-garis yang baru 45 timbul antara hub antara source dan destination 46 temp_f.x_1:=gf1[k].x_1*(1-perb)+gf2[k].x_1*perb;

47 temp_f.y_1:=gf1[k].y_1*(1-perb)+gf2[k].y_1*perb;

48 temp_f.x_2:=gf1[k].x_2*(1-perb)+gf2[k].x_2*perb;

49 temp_f.y_2:=gf1[k].y_2*(1-perb)+gf2[k].y_2*perb;

50

51 temp_f.jrk := pjgvector(temp_f.x_1,temp_f.y_1 52 ,temp_f.x_2,temp_f.y_2);

53

54 xp := (temp_f.y_2-temp_f.y_1)+temp_f.x_1;

55 yp := -(temp_f.x_2-temp_f.x_1)+temp_f.y_1;

56

57 if temp_f.jrk<>0 then 58 begin

59 hasilx:=temp_f.x_1+f*(temp_f.x_2-temp_f.x_1)+

60 d*((xp-temp_f.x_1)/temp_f.jrk);

61 hasily:=temp_f.y_1+f*(temp_f.y_2-temp_f.y_1)+

62 d*((yp-temp_f.y_1)/temp_f.jrk);

63 end;

64

65 //untuk perhitungan kalo garis Feature nya bnyk 66 if (f>=0) and (f<=1) then

67 df := abs(d) 68 else

69 if (f<0) then

70 df:=abs(pjgvector(j,i,gf1[k].x_1,gf1[k].y_1));

71 else

72 if (f>1) then

73 df:=abs(pjgvector(j,i,gf1[k].x_2,gf1[k].y_2));

74

75 dxi := hasilx-j;

76 dyi := hasily-i;

77

78 wght := 1 / (1 + df);

79

80 Dsumx := dsumx + (dxi*wght);

81 dsumy := dsumy + (dyi*wght);

82

83 wghtsum := wghtsum+wght;

84

85 end;

86

87 hasilxf:=j + (dsumx/wghtsum);

88 hasilyf:=i + (dsumy/wghtsum);

(12)

Segmen Program 4.6. Metode Field Morphing (sambungan)

89 if (hasilxf>=0)

90 and (hasilxf<=imagetempsource1.Width-1) 91 and (hasilyf>=0)

92 and (hasilyf<=imagetempsource1.Height-1) then 93 begin

94 imageframe[round(hasilxf),round(hasilyf)].R:=

95 sline^[j].R;

96 imageframe[round(hasilxf),round(hasilyf)].g:=

97 sline^[j].g;

98 imageframe[round(hasilxf),round(hasilyf)].b:=

99 sline^[j].b;

100 imageframe[round(hasilxf),round(hasilyf)].kode:=

101 true;

102 end;

103

104 end;

105 end;

106

107 interpolasihasil();

108

109 for i:=0 to image.Height-1 do 110 begin

111 sline2:=image.Picture.Bitmap.ScanLine[i];

112 for j:=0 to image.Width-1 do 113 begin

114 sline2^[j].R:=imageframe[j,i].R;

115 sline2^[j].G:=imageframe[j,i].G;

116 sline2^[j].B:=imageframe[j,i].B;

117 end;

118 end;

119

120 image.Repaint;

121 122 end;

Pada deformasi image destination tidak berbeda banyak dengan image source, hanya saja penggunaan garis pedoman berbeda. Pada saat deformasi image source, maka pedoman garis feature yang digunakan adalah garis feature 1, sedangkan untuk deformasi image destination maka garis feature yang digunakan sebagai pedoman adalah garis feature 2.

4.2.5.2. Deformation Technique

Menu deformation technique berfungsi untuk menjalankan aplikasi

dengan metode deformation techniques. Pada metode deformation techniques

(13)

digunakan juga beberapa image temporary yang digunakan untuk membimbing perubahan-perubahan yang terjadi pada setiap frame. Pada metode deformation techniques, yang diubah tidak hanya image source saja melainkan image source dan image destination. Setelah keduanya dilakukan deformasi, maka akan dilanjutkan dengan teknik penggabungan cross dissolve. Source code untuk metode deformation techniques pada image source dapat dilihat pada Segmen Program 4.7.

Segmen Program 4.7. Metode Deformation Techniques

1 procedure TImageMorphing.dt_source(jumframe : integer;

2 image : TImage);

3 var

4 i,j,k : integer;

5 dx, dy : real;

6 dx1,dy1 : real;

7 x,y,hslx,hsly : real;

8 hasilx,hasily,perb,wghtx,wghty, asilxf,hasilyf : real;

9 dsumx,dsumy, wghtsumx,wghtsumy : real;

10 temp_f : TgrsFeature;

11 jrknya,jrkx,jrky,jrkA,jrkB : real;

12 begin

13 //untuk Deformation technique dari source image 14 for i:=0 to imagetempsource1.Height-1 do

15 begin

16 sline:=imagetempsource1.Picture.Bitmap.ScanLine[i];

17 for j:=0 to imagetempsource1.Width-1 do 18 begin

19 imageframe[j][i].R:=0;//sline^[j].R;

20 imageframe[j][i].G:=0;//sline^[j].G;

21 imageframe[j][i].B:=0;//sline^[j].B;

22 imageframe[j][i].kode:=false;

23 end;

24 end;

25

26 x := 0;

27 y := 0;

28 hasilx := 0;

29 hasily := 0;

30

31 for i:=0 to imagetempsource1.Height-1 do 32 begin

33 sline:=imagetempsource1.Picture.Bitmap.ScanLine[i];

34 for j:=0 to imagetempsource1.Width-1 do 35 begin

36 hasilx := 0;

37 hasily := 0;

38 dsumx := 0;

39 dsumy := 0;

40 wghtsumx := 0; wghtsumy := 0;

(14)

Segmen Program 4.7. Metode Deformation Techniques (sambungan)

41 for k:=1 to jum_Feature do 42 Begin

43 gf2[k].jrk:=panjangvector(gf2[k].x_1,gf2[k].y_1 44 ,gf2[k].x_2,gf2[k].y_2);

45 gf1[k].jrk:=panjangvector(gf1[k].x_1,gf1[k].y_1, 46 gf1[k].x_2,gf1[k].y_2);

47 perb := (1/(jumframe-1))*(frame);

48

49 temp_f.x_1:=gf1[k].x_1*(1-perb)+gf2[k].x_1*perb;

50 temp_f.y_1:=gf1[k].y_1*(1-perb)+gf2[k].y_1*perb;

51 temp_f.x_2:=gf1[k].x_2*(1-perb)+gf2[k].x_2*perb;

52 temp_f.y_2:=gf1[k].y_2*(1-perb)+gf2[k].y_2*perb;

53

54 temp_f.jrk := pjgvector(temp_f.x_1,temp_f.y_1, 55 temp_f.x_2,temp_f.y_2);

56 if (gf1[k].y_1>gf1[k].y_2) 57 and (gf2[k].y_1<gf2[k].y_2) 58 or (gf1[k].y_1<gf1[k].y_2) 59 and (gf2[k].y_1>gf2[k].y_2) then 60 Begin

61 dx := (j-gf1[k].x_2);

62 dy := (i-gf1[k].y_1);

63 x := (temp_f.jrk/gf1[k].jrk*dx) + temp_f.x_2;

64 y := (temp_f.jrk/gf1[k].jrk*dy) + temp_f.y_1;

65 End 66 Else 67 Begin

68 dx := (j-gf1[k].x_1);

69 dy := (i-gf1[k].y_2);

70 x := (temp_f.jrk/gf1[k].jrk*dx) + temp_f.x_1;

71 y := (temp_f.jrk/gf1[k].jrk*dy) + temp_f.y_2;

72 end;

73 hslx := x-j;

74 hsly := y-i;

75

76 jrkA := pjgvector(j,i,gf1[k].x_1,gf1[k].y_1);

77 jrkB := pjgvector(j,i,gf1[k].x_2,gf1[k].y_2);

78 jrknya := jrkA+jrkB-gf1[k].jrk;

79 wghtx := 1 / (1 + abs(jrknya));

80 wghty := 1 / (1 + abs(jrknya));

81

82 Dsumx := dsumx + (hslx*wghtx);

83 dsumy := dsumy + (hsly*wghty);

84

85 wghtsumx := wghtsumx+wghtx;

86 wghtsumy := wghtsumy+wghty;

87 end;

88 hasilxf:=j + (dsumx/wghtsumx);

89 hasilyf:=i + (dsumy/wghtsumy);

(15)

Segmen Program 4.7. Metode Deformation Techniques (sambungan)

90 if (hasilxf>=0) and (hasilxf<=Width-1) 91 and (hasilyf>=0) and (hasilyf<=Height-1) 92 Then

93 Begin

94 imageframe[round(hasilxf),round(hasilyf)].R:=

95 sline^[j].R;

96 imageframe[round(hasilxf),round(hasilyf)].g:=

97 sline^[j].g;

98 imageframe[round(hasilxf),round(hasilyf)].b:=

99 sline^[j].b;

100 imageframe[round(hasilxf),round(hasilyf)].kode:=

101 true;

102 end;

103 end;

104 end;

105

106 interpolasihasil();

107

108 for i:=0 to image.Height-1 do 109 Begin

110 sline1:=image.Picture.Bitmap.ScanLine[i];

111 for j:=0 to image.Width-1 do 112 Begin

113 sline1^[j].R:=imageframe[j,i].R;

114 sline1^[j].G:=imageframe[j,i].G;

115 sline1^[j].B:=imageframe[j,i].B;

116 end;

117 end;

118

119 image.Repaint;

120 end;

121 end;

Pada metode deformation technique, deformasi image destination tidak berbeda banyak dengan image source, hanya saja penggunaan garis feature yang berbeda. Pada saat frame pertama di image destination, maka gambar akan ditarik sesuai dengan image source dikarenakan image source merupakan image awal yang nantinya akan diubah.

4.2.6. Menu Movie

Pada menu movie hanya terdapat 1 fasilitas yang dapat digunakan oleh

user. Menu yang ada pada menu movie berguna untuk melakukan morphing pada

file video. Pada Gambar 4.7. dapat dilihat item yang ada pada menu movie.

(16)

Gambar 4.7. Menu Movie 4.2.6.1. Video Morphing

Video morphing merupakan menu untuk melakukan morphing pada sebuah file movie. File movie yang diterima oleh aplikasi ini adalah file dengan format AVI. Pada proses video morphing, maka user akan memasukkan 2 buah file AVI sehingga akan dibentuk sebuah perubahan dari file AVI source menjadi file AVI destination.

4.2.7. Menu Others

Pada menu others terdapat 2 fasilitas yang dapat digunakan oleh user, yaitu submeu help dan created. Menu others dimaksudkan untuk membantu user dalam menggunakan aplikasi morphing. ada menu movie hanya terdapat 1 fasilitas yang dapat digunakan oleh user. Pada Gambar 4.8, dapat dilihat item yang ada pada menu movie.

Gambar 4.8. Menu Others

4.2.8. Proses Cross Dissolve

Proses cross dissolve yang digunakan pada setiap akhir metode image

morphing, mempunyai algoritma yang membuat sebuah image semakin lama

menjadi semakin transparan dengan mengalikan nilai-nilai pixel yang terdiri dari

R, G, dan B dengan sebuah nilai perbandingan yang didapat dari hasil

perbandingan antara frame dan jumlah frame. Keseluruhan source code dapat

dilihat pada Segmen Program 4.8.

(17)

Segmen Program 4.8. Metode Cross Dissolve

1 procedure

2 crossdissolve(img1,img2:timage;jumframe:integer);

3 var

4 i,j:integer;

5 perb:real;

6 Begin

7 for i:=0 to img1.picture.bitmap.Height-1 do 8 Begin

9 sline:=img1.Picture.Bitmap.ScanLine[i];

10 sline1:=img2.Picture.Bitmap.ScanLine[i];

11 sline2:=imagetemp.Picture.Bitmap.ScanLine[i];

12

13 perb:=(jumframe-frame)/(jumframe);

14

15 for j:=0 to img1.picture.bitmap.Width-1 do 16 Begin

17 sline2^[j].R:=round((sline^[j].R *

18 perb)+(sline1^[j].R * (1-perb));

19 sline2^[j].G:=round((sline^[j].G *

20 perb)+(sline1^[j].G * (1-perb));

21 sline2^[j].B:=round((sline^[j].B *

22 perb)+(sline1^[j].B * (1-perb));

23 end;

24 end;

25

26 if frame<jumframe then 27 inc(frame);

28

29 imagetemp.Repaint;

30 imagehasil.Picture:=imagetemp.Picture;

31 end;

4.2.9. Button Resize

Button resize diberikan untuk memudahkan user menggunakan aplikasi dengan ukuran gambar yang berbeda. Button resize hanya akan dapat dijalankan apabila kedua file image mempunyai ukuran yang berbeda. Apabila ukuran kedua image berbeda, maka user dapat memilih image mana yang ingin diubah ukurannya. Keseluruhan source code untuk mengubah ukuran image dapat dilihat pada Segmen Program 4.9.

Segmen Program 4.9. Merubah Ukuran Image

1 procedure TImageMorphing.interpolasi(image : TImage;

2 w,h,w1,h1 : integer);

3 var

4 y,x,x1,y1 : integer;

5 PC,PH : PByteArray;

(18)

Segmen Program 4.9. Merubah Ukuran Image

6 xasal,yasal,wxL,wyT,sh,sv : real;

7 Ki,Ri,Gi,Bi,Ko,Ro,Go,Bo : array of array of byte;

8 xL,xR,yT,yB : integer;

9 begin

10 sh := w1/w;

11 sv := h1/h;

12

13 if (image.Picture.Bitmap.PixelFormat = pf24bit) then 14 begin

15 SetLength(Ri, w, h);

16 SetLength(Gi, w, h);

17 SetLength(Bi, w, h);

18 SetLength(Ro, w1, h1);

19 SetLength(Go, w1, h1);

20 SetLength(Bo, w1, h1);

21

22 for y := 0 to h-1 do 23 begin

24 PC := image.Picture.Bitmap.ScanLine[y];

25 for x := 0 to w-1 do 26 begin

27 Bi[x,y] := PC[3*x];

28 Gi[x,y] := PC[3*x+1];

29 Ri[x,y] := PC[3*x+2];

30 end;

31 end;

32 for x1 := 0 to w1-1 do 33 for y1 := 0 to h1-1 do 34 begin

35 xasal := x1/sh;

36 yasal := y1/sv;

37 if ((floor(xasal)<0) or (ceil(xasal)>w-1) or 38 (floor(yasal)<0) or (ceil(yasal)>h-1)) then 39 begin

40 Ro[x1,y1] := 255;

41 Go[x1,y1] := 255;

42 Bo[x1,y1] := 255;

43 end 44 else 45 begin

46 xL := Floor(xasal);

47 xR := ceil(xasal);

48 yT := Floor(yasal);

49 yB := ceil(yasal);

50 wxL := xR-xasal;

51 wyt := yB-yasal;

52 Ro[x1,y1] := round(wxL*wyT*Ri[xL,yT]+(1- 53 wxL)*wyT*Ri[xR,yT]+wxL*(1-wyT)*Ri[xL,yB]+

54 (1-wxL)*(1-wyT)*Ri[xR,yB]);

55 Go[x1,y1] := round(wxL*wyT*Gi[xL,yT]+(1- 56 wxL)*wyT*Gi[xR,yT]+wxL*(1-wyT)*Gi[xL,yB]+

57 (1-wxL)*(1-wyT)*Gi[xR,yB]);

58 Bo[x1,y1] := round(wxL*wyT*Bi[xL,yT]+(1- 59 wxL)*wyT*Bi[xR,yT]+wxL*(1-wyT)*Bi[xL,yB]+

(19)

Segmen Program 4.9. Merubah Ukuran Image (sambungan)

60 (1-wxL)*(1-wyT)*Bi[xR,yB]);

61 end;

62 end;

63 image.Picture.Bitmap.Width:=w1;

64 image.Picture.Bitmap.Height:=h1;

65

66 for y1 :=0 to h1-1 do 67 begin

68 PH := image.Picture.Bitmap.ScanLine[y1];

69 for x1 := 0 to w1-1 do 70 begin

71 PH[3*x1] := Bo[x1,y1];

72 PH[3*x1+1] := Go[x1,y1];

73 PH[3*x1+2] := Ro[x1,y1];

74 end 75 end;

76 Ri := nil;

77 Gi := nil;

78 Bi := nil;

79 Ro := nil;

80 Go := nil;

81 Bo := nil;

82 if radiobutton1.Checked=true then 83 begin

84 imagesource.Width:=image.Width;

85 imagesource.Height:=image.Height;

86 imagesource.Picture:=image.Picture;

87

88 imagetempsource1.Width:=image.Width;

89 imagetempsource1.Height:=image.Height;

90 imagetempsource1.Picture:=image.Picture;

91

92 imagetempsource2.Width:=image.Width;

93 imagetempsource2.Height:=image.Height;

94 imagetempsource2.Picture:=image.Picture;

95

96 end 97 else

98 if radiobutton2.Checked=true then 99 begin

100 imagedest.Width:=image.Width;

101 imagedest.Height:=image.Height;

102 imagedest.Picture:=image.Picture;

103

104 imagetempdest1.Width:=image.Width;

105 imagetempdest1.Height:=image.Height;

106 imagetempdest1.Picture:=image.Picture;

107

108 imagetempdest2.Width:=image.Width;

109 imagetempdest2.Height:=image.Height;

110 imagetempdest2.Picture:=image.Picture;

111

112 imagedest.Refresh;

113 imagetempdest1.Refresh;

(20)

Segmen Program 4.9. Merubah Ukuran Image (sambungan)

114 imagetempdest2.Refresh;

115 end;

116 end;

117 end;

4.2.10. Cara Kerja Aplikasi Video Morphing

Langkah pertama yang dilakukan dalam aplikasi video morphing adalah memisahkan frame-frame yang ada dalam sebuah file AVI. Setelah didapatkan frame awal dan frame akhir, maka langkah selanjutnya adalah memberikan garis feature di setiap image. Setiap frame akan dilakukan proses morphing sendiri- sendiri. Dilakukan setiap frame agar didapatkan frame sesuai dengan posisi yang ada. Algoritma secara keseluruhan untuk video morphing dapat dilihat pada segmen program 4.10.

Segmen Program 4.10. Algoritma Video Morphing

1 if (label1.Caption<>'') and (label2.Caption<>'') then 2 begin

3 if (FrmCnt1=FrmCnt2) and (AVIWidth=AVIWidth2) 4 and (AVIHeight=AVIHeight2) then

5 begin

6 bitbtn1.Enabled:=false;

7 bitbtn2.enabled:=false;

8 imagedest1.Picture.Bitmap.PixelFormat:=pf24bit;

9 imagetempdest11.Picture.Bitmap.PixelFormat:=

10 pf24bit;

11 imagetempdest12.Picture.Bitmap.PixelFormat:=

12 pf24bit;

13 imagetempdest13.Picture.Bitmap.PixelFormat:=

14 pf24bit;

15

16 imagedest2.Picture.Bitmap.PixelFormat:=pf24bit;

17 imagetempdest21.Picture.Bitmap.PixelFormat:=

18 pf24bit;

19 imagetempdest22.Picture.Bitmap.PixelFormat:=

20 pf24bit;

21 imagetempdest23.Picture.Bitmap.PixelFormat:=

22 pf24bit;

23 image_temp.Picture.Bitmap:=

24 imagesource1.Picture.Bitmap;

25 image_temp.visible:=false;

26 image_temp.Picture.Bitmap.PixelFormat:=pf24bit;

(21)

Segmen Program 4.10. Algoritma Video Morphing (sambungan)

27

28 imgsource1.Picture.Bitmap.PixelFormat:=pf24bit;

29 imagetempsource11.Picture.Bitmap.PixelFormat:=

30 pf24bit;

31 imagetempsource12.Picture.Bitmap.PixelFormat:=

32 pf24bit;

33 imagetempsource13.Picture.Bitmap.PixelFormat:=

34 pf24bit;

35

36 imagesource2.Picture.Bitmap.PixelFormat:=pf24bit;

37 pf24bit;

38 imagetempsource21.Picture.Bitmap.PixelFormat:=

39 pf24bit;

40 imagetempsource22.Picture.Bitmap.PixelFormat:=

41 pf24bit;

42 imagetempsource23.Picture.Bitmap.PixelFormat:=

43 pf24bit;

44 imagetemp.Picture.Bitmap:=

45 imagetempsource11.Picture.Bitmap;

46 imagetemp.Picture.Bitmap.PixelFormat:=pf24bit;

47

48 frame:=0;

49 jum_frame:=FrameCount1-1;

50

51 jum_feature:=jum_feature-1;

52

53 tm := gettime();

54 if (feature_m1[1].x_1<>0) and 55 (feature_m1[1].y_1<>0) and

56 (feature_m1[1].x_2<>imagetempsource21.Width-1) 57 and (feature_m1[1].y_2<>0) then

58 begin

59 jum_feature:=jum_feature+4;

60 for i:=jum_feature downto 5 do 61 begin

62 feature_m1[i]:=feature_m1[i-4];

63 feature_m2[i]:=feature_m2[i-4];

64 feature_m3[i]:=feature_m3[i-4];

65 feature_m4[i]:=feature_m4[i-4];

66 end;

67

68 //inisialisasi garis fea 1 69 feature_m1[1].x_1:=0;

70 feature_m1[1].y_1:=0;

71

72 feature_m1[1].x_2:=

73 imagesource2.picture.bitmap.Width-1;

74 feature_m1[1].y_2:=0;

75

76 feature_m2[1]:=feature_m1[1];

77 feature_m3[1]:=feature_m1[1];

78 feature_m4[1]:=feature_m1[1];

(22)

Segmen Program 4.10. Algoritma Video Morphing (sambungan)

79

80 //inisialisasi garis fea 2 81 feature_m1[2].x_1:=

82 imagesource2.Picture.bitmap.Width-1;

83 feature_m1[2].y_1:=0;

84

85 feature_m1[2].x_2:=

86 imagesource2.picture.bitmap.Width-1;

87 feature_m1[2].y_2:=

88 imagesource2.picture.bitmap.Height-1;

89

90 feature_m2[2]:=feature_m1[2];

91 feature_m3[2]:=feature_m1[2];

92 feature_m4[2]:=feature_m1[2];

93

94 //inisialisasi garis fea 3 95 feature_m1[3].x_1:=0;

96 feature_m1[3].y_1:=

97 imagesource2.picture.bitmap.height-1;

98 feature_m1[3].y_2:=

99 imagesource2.picture.bitmap.Height-1;

100

101 feature_m2[3]:=feature_m1[3];

102 feature_m3[3]:=feature_m1[3];

103 feature_m4[3]:=feature_m1[3];

104

105 //inisialisasi garis fea 4 106 feature_m1[4].x_1:=0;

107 feature_m1[4].y_1:=0;

108 feature_m1[4].x_2:=0;

109 feature_m1[4].y_2:=

110 imagesource2.picture.bitmap.Height-1;

111

112 feature_m2[4]:=feature_m1[4];

113 feature_m3[4]:=feature_m1[4];

114 feature_m4[4]:=feature_m1[4];

115 end;

116

117 gauge1.Visible:=true;

118 gauge1.MaxValue:=jum_frame;

119 gauge1.MinValue:=0;

120 Application.ProcessMessages;

121

122 jum:=jum_feature;

123

124 while frame<=jum_frame do 125 begin

126 perb := (1/(jum_frame-1))*(frame);

127 frame_temp:=0;

128

(23)

Segmen Program 4.10. Algoritma Video Morphing (sambungan)

129 for i:=1 to jum_feature do 130 begin

131 feature_t_s[i].x_1:=feature_m1[i].x_1*

132 (1-perb)+feature_m3[i].x_1*perb;

133 feature_t_s[i].x_2:=feature_m1[i].x_2*

134 (1-perb)+feature_m3[i].x_2*perb;

135 feature_t_s[i].y_1:=feature_m1[i].y_1*

136 (1-perb)+feature_m3[i].y_1*perb;

137 feature_t_s[i].y_2:=feature_m1[i].y_2*

138 (1-perb)+feature_m3[i].y_2*perb;

139

140 feature_t_s[i].jrk := imagemorphing.

141 panjangvector(feature_t_s[i].x_1, 142 feature_t_s[i].y_1,feature_t_s[i].x_2, 143 feature_t_s[i].y_2);

144

145 feature_t_d[i].x_1:=feature_m2[i].x_1*

146 (1-perb)+feature_m4[i].x_1*perb;

147 feature_t_d[i].x_2:=feature_m2[i].x_2*

148 (1-perb)+feature_m4[i].x_2*perb;

149 feature_t_d[i].y_1:=feature_m2[i].y_1*

150 (1-perb)+feature_m4[i].y_1*perb;

151 feature_t_d[i].y_2:=feature_m2[i].y_2*

152 (1-perb)+feature_m4[i].y_2*perb;

153

154 feature_t_d[i].jrk := imagemorphing.

155 panjangvector(feature_t_d[i].x_1, 156 feature_t_d[i].y_1,feature_t_d[i].x_2, 157 feature_t_d[i].y_2);

158 end;

159

160 imagetempsource23.Picture.Bitmap:=

161 imagets[frame].Picture.Bitmap;

162 imagetempdest23.Picture.Bitmap:=

163 imagetd[frame].Picture.Bitmap;

164

165 while frame_temp<=jum_frame do 166 begin

167 ubah_dest(frame,jum_frame,imageframed[frame], 168 imagetempdest23,feature_t_s,feature_t_d);

169 ubah_source(frame,jum_frame,imageframes[frame]

170 ,imagetempsource23,feature_t_s, 171 feature_t_d);

172

173 crossdissolve(imageframes[frame],

174 imageframed[frame],frame_temp,jum_frame);

175

176 inc(frame_temp);

177 imagehsl1[frame_temp-1].picture:=

178 image_temp.picture;

179 end;

(24)

Segmen Program 4.10. Algoritma Video Morphing (sambungan)

180 imagehslsemua[frame].Picture.Bitmap :=

181 imagehsl1[frame].Picture.Bitmap;

182 image_temp.Picture.Bitmap:=

183 imagehsl1[frame].Picture.Bitmap;

184 inc(frame);

185 gauge1.Progress:=frame;

186 end;

187 tm2:=gettime();

188 ImageMorphing.hitung_time(tm,tm2);

189 gauge1.visible:=false;

190 191

192 frame:=0;

193 form1.Show;

194

195 imagetempsource13.Picture.Bitmap:=

196 imagetempsource12.Picture.Bitmap;

197 imagetempdest13.Picture.Bitmap:=

198 imagetempdest12.Picture.Bitmap;

199

200 imagetempsource23.Picture.Bitmap:=

201 imagetempsource22.Picture.Bitmap;

202 imagetempdest23.Picture.Bitmap:=

203 imagetempdest22.Picture.Bitmap;

204

205 frame:=0;

206 Form1.ScrollBar1.Max:=jum_frame-1;

207

208 bitbtn1.Enabled:=true;

209 bitbtn2.enabled:=true;

210 jum_feature:=jum_feature+1;

211 end 212 else

213 showmessage('Size or frame not same');

214 end 215 else

216 showmessage('Open All AVI File First');

217 end;

4.2.11. Form Hasil

Form hasil digunakan untuk menampilkan hasil morphing dari dua buah

file AVI. Form hasil hanya diperuntukkan untuk melihat hasil. Fasilitas untuk

menyimpan hasil ada pada form utama. Tampilan dari form hasil dapat dilihat

pada Gambar 4.9

(25)

Gambar 4.9. Form Hasil

Gambar

Gambar 4.1. Tampilan Form Utama Image Morphing
Gambar 4.2. Tampilan Form Video Morphing
Gambar 4.4. SubMenu Open Image
Gambar 4.5. SubMenu Export Hasil
+2

Referensi

Dokumen terkait

Pihak-pihak yang berperan dalam rapat tersebut adalah Dosen Pembimbing, Kepala Studio, Staf Studio, Koordinator Kolokium TA, Mahasiswa peserta TA, dan Koordinator TA.. Rapat

Dalam penelitian ini, Variabel yang diambil dalam kebijakan penyusunan anggaran adalah kemampuan seorang manajer atau aparat pemerintahan mengenai pengelolaan

Tanda yang ada sedemikian rupa sebagai kemungkinan, tanpa tergantung pada adanya sebuah denotatum, tetapi dapat dikaitkan dengannya atas dasar suatu persamaan yang secara potensial

Penelitian ini dilakukan pada pekerja Bengkel Las di Jalan Mahkamah Kecamatan Medan Kota tahun 2017 dengan tujuan untuk mengetahui hubungan intensitas getaran

Pada bulan Agustus 2017, kelompok yang memberikan andil/sumbangan terhadap deflasi adalah kelompok bahan makanan sebesar 0,45 persen dan kelompok transpor,

bahwa berdasarkan pertimbangan sebagaimana dimaksud dalam huruf a, serta memperhatikan Surat Edaran Menteri Dalam Negeri Nomor 900/2677/SJ tanggal 8 Nopember 2007, hal Hibah

Menetapkan beban kerja bersama dengan anggota tim peneliti lainnya 12 pertemuan dengan membahas aplikasi dan laporan serta modul pelatihan 12 pertemuan dengan

Pengelompokkan obyek wisata dibagi menjadi 6 satuan kawasan wisata berdasarkan daya tarik yang terdiri dari obyek-obyek wisata yang mempunyai potensi sedang,