Vous êtes sur la page 1sur 4

JAWABAN UAS Praktikum PCD : Kelompok A: procedure TForm1.Button1Click(Sender: TObject); begin if (opd.Execute) then begin gb1.Picture.LoadFromFile(opd.FileName); gb2.Picture.LoadFromFile(opd.

FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); var br , kl , i,j : integer; temp :byte; dbaris1, dbaris1a, dbaris1b , dbaris2 : pbytearray; n : array[1..9] of byte; begin for br := 1 to gb1.Height-2 do begin for kl := 1 to gb1.Width-2 do begin dbaris1a := gb1.Picture.Bitmap.ScanLine[br-1]; dbaris1 := gb1.Picture.Bitmap.ScanLine[br]; dbaris1b := gb1.Picture.Bitmap.ScanLine[br+1]; dbaris2 := gb2.Picture.Bitmap.ScanLine[br]; // gambar gray scale if (form1.gb1.Picture.Bitmap.PixelFormat = pf8bit) then begin n[1]:=dbaris1a[kl-1]; n[2]:=dbaris1a[kl]; n[3]:=dbaris1a[kl+1]; n[4]:=dbaris1[kl-1]; n[5]:=dbaris1[kl]; n[6]:=dbaris1[kl+1]; n[7]:=dbaris1b[kl-1]; n[8]:=dbaris1b[kl]; n[9]:=dbaris1b[kl+1]; for i:=1 to 8 do begin for j:=1 to 8 do begin if (n[j] > n[j+1]) then begin temp:=n[j]; n[j]:=n[j+1]; n[j+1]:=temp; end; end; end; dbaris2[kl] := n[5]; end; end; end; gb2.Repaint; end;

JAWABAN UAS Praktikum PCD : Kelompok B: procedure TForm1.Button1Click(Sender: TObject); begin if (opd.Execute) then begin Form1.gb1.Picture.LoadFromFile(opd.FileName); Form1.gb2.Picture.LoadFromFile(opd.FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); var br , kl : integer; baru:integer; dbaris1a , dbaris1b ,dbaris1c ,dbaris2 : pbytearray; begin for br := 1 to gb1.Height-2 do begin for kl := 1 to gb1.Width-2 do begin dbaris1a := gb1.Picture.Bitmap.ScanLine[br-1]; dbaris1b := gb1.Picture.Bitmap.ScanLine[br]; dbaris1c := gb1.Picture.Bitmap.ScanLine[br+1]; dbaris2 := gb2.Picture.Bitmap.ScanLine[br]; baru := ((-1*dbaris1a[kl-1])+(-1*dbaris1a[kl])+(-1*dbaris1a[kl+1])+(-1*dbaris1b[kl-1])+ (8*dbaris1b[kl])+(-1*dbaris1b[kl+1])+(-1*dbaris1c[kl-1])+(-1*dbaris1c[kl])+(-1*dbaris1c[kl+1])); if baru > 255 then baru:=255; if baru < 0 then baru:=0; dbaris2[kl]:=baru; end; end; // tampilkan hasilnya dan hitung histogramnya gb2.Repaint; end;

JAWABAN UAS Praktikum PCD : Kelompok C: procedure TForm1.Button1Click(Sender: TObject); begin if (opd.Execute) then begin Form1.gb1.Picture.LoadFromFile(opd.FileName); Form1.gb2.Picture.LoadFromFile(opd.FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); var i, j: integer; cKum : array [0..255] of integer; Ko : array [0..255] of byte; dbaris1,dbaris2: PByteArray; begin for i:= 0 to 255 do cKum[i]:=0;; for i:= 0 to gb1.Height-1 do begin dbaris1:= gb1.Picture.BitMap.ScanLine[i]; for j:= 0 to gb1.Width-1 do Inc(cKum[dbaris1[j]]); end; for i := 1 to 255 do cKum[i] := cKum[i-1]+cKum[i]; for i := 0 to 255 do Ko[i] := Round(255*(cKum[i]/(gb1.Width*gb1.Height))); for i:= 0 to gb1.Height-1 do begin dbaris1:= gb1.Picture.BitMap.ScanLine[i]; dbaris2:= gb2.Picture.BitMap.ScanLine[i]; for j:= 0 to gb1.Width-1 do dbaris2[j] := Ko[dbaris1[j]]; end; gb2.Repaint; end;

JAWABAN UAS Praktikum PCD : Kelompok D: procedure TForm1.Button2Click(Sender: TObject); var histogram: array[0..255] of integer; dbaris1, dbaris2: PByteArray; TotalMean, Variance, maxVariance, zerothCumuMoment, firstCumuMoment : real; i,j,k: integer; p: PByteArray; threshold:byte; area: Longint; begin for i:=0 to 255 do begin histogram[i]:=0; end; for i:=0 to gb1.Height-1 do begin dbaris1:=gb1.Picture.Bitmap.ScanLine[i]; for j:= 0 to gb1.Width-1 do begin histogram[dbaris1[j]]:=histogram[dbaris1[j]]+1; end; end; threshold:=0; totalMean := 0; maxVariance := 0; firstCumuMoment := 0; zerothCumuMoment := 0; area := (gb1.Height * gb1.Height); for k:= 0 to 255 do TotalMean := TotalMean + ((k * histogram[k]) / area); for k:= 0 to 255 do begin zerothCumuMoment := zerothCumuMoment + histogram[k] / area; firstCumuMoment := firstCumuMoment + (k * histogram[k] / area); variance := totalMean * zerothCumuMoment - firstCumuMoment; variance := variance * variance; if ((zerothCumuMoment <> 0) and (zerothCumuMoment <> 1)) then begin variance := variance /(zerothCumuMoment * (1 - zerothCumuMoment)); if (maxVariance < variance) then begin maxVariance := variance; threshold := k; end; end; end; for i:=0 to gb1.Height-1 do begin dbaris1:= gb1.Picture.Bitmap.ScanLine[i]; dbaris2:= gb2.Picture.Bitmap.ScanLine[i]; for j:=0 to gb1.Width-1 do begin if (dbaris1[j]) >= threshold then dbaris2[j]:= 255 else dbaris2[j]:= 0; end; end; gb2.Repaint; end;