You are on page 1of 8

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, jpe g, Dialogs, ExtCtrls,

StdCtrls, TeEngine, Series, TeeProcs, Chart, ComCtrls; type TForm1 = class(TForm) PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; TabSheet4: TTabSheet; TabSheet5: TTabSheet; Button1: TButton; Button2: TButton; Button3: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Chart1: TChart; Series1: TLineSeries; Series2: TLineSeries; Series3: TLineSeries; Edit7: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Button4: TButton; Image1: TImage; Panel1: TPanel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Image2: TImage; OpenDialog1: TOpenDialog; Chart2: TChart; Series4: TLineSeries; Chart3: TChart; LineSeries1: TLineSeries; Image3: TImage; Edit8: TEdit; Label7: TLabel; Label8: TLabel; Edit9: TEdit; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label13: TLabel; GroupBox1: TGroupBox; GroupBox2: TGroupBox; GroupBox3: TGroupBox; Panel2: TPanel; Label12: TLabel;

Label14: TLabel; Label15: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Jpgku: TJPEGImage; Bmpku, BMPAnalisa1, BMPGS:TBitmap; HistogramR, HistogramG, HistogramB : array [0..256] of Integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin if OpenDialog1.Execute then begin JpgKu.LoadFromFile(OpenDialog1.FileName); JpgKu.DIBNeeded; //PageControl1.Width:= JpgKu.Width; //PageControl1.Height:= JpgKu.Height; Image1.Width:=JpgKu.Width; Image1.Height:=JpgKu.Height; Image2.Width:=JpgKu.Width; Image2.Height:=JpgKu.Height; Bmpku.Assign(JpgKu); Image1.Picture.Assign(Bmpku); for i:=0 to 255 do begin HistogramR[i]:=0; HistogramG[i]:=0; HistogramB[i]:=0; end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin JpgKu:= TJPEGImage.Create; Bmpku:=TBitmap.Create; BMPGS:=TBitmap.Create; BMPAnalisa1:=TBitmap.Create; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin JpgKu.Free; Bmpku.Free; BMPAnalisa1.Free; BMPGS.Free; end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var R,G,B:word; begin R:= GetRValue(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]); G:= GetGValue(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]); B:= GetBValue(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]); Label4.Caption:=inttostr(R); Label5.Caption:=inttostr(G); Label6.Caption:=inttostr(B); end;

procedure TForm1.Button2Click(Sender: TObject); var i,j,batasbawah :integer; R,G,B:word; datarR,datarG,datarB:boolean; maxRx, minRx, maxGx, minGx, maxBx, minBx, batasBG_R,batasBG_G,batasBG_B, posisiPuncakR,posisiPuncakG,posisiPuncakB, puncakHistogramR,puncakHistogramG,puncakHistogramB:integer; begin for i:=1 to Bmpku.Width-1 do begin for j:=1 to Bmpku.Height-1 do begin R:= GetRValue(Bmpku.Canvas.Pixels[i,j]); G:= GetGValue(Bmpku.Canvas.Pixels[i,j]); B:= GetBValue(Bmpku.Canvas.Pixels[i,j]); inc(HistogramR[R]); inc(Histogramg[g]); inc(HistogramB[b]); end; end; Series1.Clear; Series2.Clear; Series3.Clear; puncakHistogramR:=0; puncakHistogramG:=0; puncakHistogramB:=0; batasBG_R:=0; batasBG_G:=0; batasBG_B:=0; maxRx:=0; minRx:=0; maxGx:=0; minGx:=0; maxBx:=0; minBx:=0; batasbawah:=500; //maksimum minimum Red

begin for i:=1 to 255 do begin Series1.AddXY(i,HistogramR[i],'',clred); if (HistogramR[i]>puncakHistogramR) then begin posisiPuncakR:=i; puncakHistogramR:=HistogramR[i]; end; //Series2.AddXY(i,HistogramG[i],'',clGreen); //Series3.AddXY(i,HistogramB[i],'',clBlue); //Label16.Caption:=inttostr(posisiPuncakR); end; for i:= posisiPuncakR downto 1 do if (batasBG_R=0) and (HistogramR[i]<batasbawah) then batasBG_R:=i; puncakHistogramR:=0; for i:=1 to batasBG_R do begin if (HistogramR[i]>puncakHistogramR) then begin posisiPuncakR:=i; puncakHistogramR:=HistogramR[i]; end; end; Label15.Caption:=inttostr(posisiPuncakR); //Label16.Caption:=inttostr(puncakHistogramR); for i:= posisiPuncakR downto 1 do if (minRx=0) and (HistogramR[i]<batasbawah) then minRx:=i; //Label17.Caption:=inttostr(minRx); edit2.Text:=inttostr(minRx); if minRx=i then inc(i); maxRx:=0; for i:=posisiPuncakR to batasBG_R do if (maxRx=0) and (HistogramR[i]<batasbawah) then maxRx:=i; //Label18.Caption:=inttostr(maxRx); edit1.Text:=inttostr(maxRx); end; //maksimum minimum Green begin for i:=1 to 255 do begin //Series1.AddXY(i,HistogramR[i],'',clred); if (HistogramG[i]>puncakHistogramG) then begin posisiPuncakG:=i; puncakHistogramG:=HistogramG[i]; end; //Series2.AddXY(i,HistogramG[i],'',clGreen); //Series3.AddXY(i,HistogramB[i],'',clBlue);

end; for i:= posisiPuncakG downto 1 do if (batasBG_G=0) and (HistogramG[i]<batasbawah) then batasBG_G:=i; //label22.Caption:=inttostr(BatasBG_G); puncakHistogramG:=0; for i:=1 to batasBG_G do begin if (HistogramG[i]> puncakHistogramG) then begin posisiPuncakG:=i; puncakHistogramG:=HistogramG[i]; end; // Label22.Caption:=inttostr(posisiPuncakG); end; for i:= posisiPuncakG downto 1 do if (minGx=0) and (HistogramG[i]<batasbawah) then minGx:=i; //Label23.Caption:=inttostr(minGx); edit4.Text:=inttostr(minGx); if minGx=i then inc(i); maxGx:=0; for i:=posisiPuncakG to batasBG_G do if (maxGx=0) and (HistogramG[i]<batasbawah) then maxGx:=i; //Label22.Caption:=inttostr(maxGx); edit3.Text:=inttostr(maxGx); end; //maksimum minimum Blue begin for i:=1 to 255 do begin //Series1.AddXY(i,HistogramR[i],'',clred); if (HistogramB[i]>puncakHistogramB) then begin posisiPuncakB:=i; puncakHistogramB:=HistogramB[i]; end; //Series2.AddXY(i,HistogramG[i],'',clGreen); //Series3.AddXY(i,HistogramB[i],'',clBlue); end; for i:= posisiPuncakB downto 1 do if (batasBG_B=0) and (HistogramB[i]<batasbawah) then batasBG_B:=i; //label22.Caption:=inttostr(BatasBG_G); puncakHistogramB:=0; for i:=1 to batasBG_B do begin if (HistogramG[i]> puncakHistogramB) then begin posisiPuncakB:=i;

puncakHistogramB:=HistogramB[i]; end; //Label23.Caption:=inttostr(posisiPuncakB); end; for i:= posisiPuncakB downto 1 do if (minBx=0) and (HistogramB[i]<batasbawah) then minBx:=i; //Label25.Caption:=inttostr(minBx); edit6.Text:=inttostr(minBx); if minBx=i then inc(i); maxBx:=0; for i:=posisiPuncakB to batasBG_B do if (maxBx=0) and (HistogramB[i]<batasbawah) then maxBx:=i; //Label24.Caption:=inttostr(maxBx); edit5.Text:=inttostr(maxBx); end; end; procedure TForm1.Button4Click(Sender: TObject); var i,j,luasR,luasG,luasB,batasMinimal:integer; R,G,B,GS :word; begin luasR:=0; luasG:=0; luasB:=0; batasMinimal:= strtoint(Edit7.Text); for i:=1 to 255 do begin if HistogramR[i]>batasMinimal then luasR:= luasR+ (HistogramR[i]-batasMi nimal); if HistogramG[i]>batasMinimal then luasG:= luasG+ (HistogramG[i]-batasMi nimal); if HistogramB[i]>batasMinimal then luasB:= luasB+ (HistogramB[i]-batasMi nimal); end; Label1.Caption:=inttostr(luasR); Label2.Caption:=inttostr(luasG); Label3.Caption:=inttostr(luasB); BMPGS.Assign(Bmpku); for i:=1 to Bmpku.Width-1 do begin for j:=1 to Bmpku.Height-1 do begin R:= GetRValue(Bmpku.Canvas.Pixels[i,j]); G:= GetGValue(Bmpku.Canvas.Pixels[i,j]); B:= GetBValue(Bmpku.Canvas.Pixels[i,j]); GS:=Round((luasR*R+luasG*G+luasB*B)/(luasR+luasG+luasB));

BMPGS.Canvas.Pixels[i,j]:=RGB(Gs,Gs,Gs); end; end; Image2.Picture.Assign(BMPGS); end; procedure TForm1.Button3Click(Sender: TObject); var i,j,itungany:integer; R,G,B,GS,RRA,RRB,GGA,GGB,BBA,BBB :word; yy,xx,itunganx,Xawal,Xakhir,Yawal,yakhir:integer; begin BMPAnalisa1.Assign(Bmpku); RRA:=strtoint(Edit1.Text); RRB:=strtoint(Edit2.Text); GGA:=strtoint(Edit3.Text); GGB:=strtoint(Edit4.Text); BBA:=strtoint(Edit5.Text); BBB:=strtoint(Edit6.Text); Series4.Clear; LineSeries1.Clear; Xawal:=0; Xakhir:=0; Yawal:=0; yakhir:=0; for j:=1 to Bmpku.Height-1 do begin itunganx:=0; for i:=1 to Bmpku.Width-1 do begin R:= GetRValue(Bmpku.Canvas.Pixels[i,j]); G:= GetGValue(Bmpku.Canvas.Pixels[i,j]); B:= GetBValue(Bmpku.Canvas.Pixels[i,j]); if (RRA>R) and (RRB<R) and (GGA>G) and (GGB<G) and (BBA>B) and (BBB<B) then begin inc(itunganx); end end; xx:=StrToInt(Edit8.text); if (itunganx>xx) and (yawal=0) then yawal:=j; if (itunganx>xx) then yakhir:=j; LineSeries1.AddXY(j,itunganx,'',clblue); end; for i:=1 to Bmpku.Width-1 do begin itungany:=0; for j:=1 to Bmpku.Height-1 do begin R:= GetRValue(Bmpku.Canvas.Pixels[i,j]); G:= GetGValue(Bmpku.Canvas.Pixels[i,j]); B:= GetBValue(Bmpku.Canvas.Pixels[i,j]);

if (RRA>R) and (RRB<R) and (GGA>G) and (GGB<G) and (BBA>B) and (BBB<B) then begin BMPAnalisa1.Canvas.Pixels[i,j]:=RGB(0,0,0); inc(itungany); end else BMPAnalisa1.Canvas.Pixels[i,j]:=RGB(255,255,255); end; yy:=StrToInt(Edit9.text); if (itungany>yy) and (xawal=0) then xawal:=i; if (itungany>yy) then xakhir:=i; Series4.AddXY(i,itungany,'',clblue); end; //ShowMessage(inttostr(yawal)); BMPAnalisa1.Canvas.MoveTo(0,yawal); BMPAnalisa1.Canvas.LineTo(BMPAnalisa1.Width,yawal); //Untuk Menggambar Y Akhir //ShowMessage(inttostr(yakhir)); BMPAnalisa1.Canvas.MoveTo(0,yakhir); BMPAnalisa1.Canvas.LineTo(BMPAnalisa1.Width,yakhir); //Untuk Menggambar X Awal BMPAnalisa1.Canvas.MoveTo(Xawal,0); BMPAnalisa1.Canvas.LineTo(Xawal,BMPAnalisa1.Height); //Untuk Menggambar X Akhir BMPAnalisa1.Canvas.MoveTo(Xakhir,0); BMPAnalisa1.Canvas.LineTo(Xakhir,BMPAnalisa1.Height); Image3.Picture.Assign(BMPAnalisa1); end; end.

You might also like