Anda di halaman 1dari 3

procedure histogram; var hasil : string; br,kl, lop, data, mak , y1 , y2, makr,makg,makb: integer; dbaris : pbytearray; h,hr,hg,hb

: array[0..255] of integer; tinggi : integer; begin for lop := 0 to 255 do begin h[lop] := 0; hr[lop] := 0; hg[lop] := 0; hb[lop] := 0; end;

if (form1.gb1.Picture.Bitmap.PixelFormat = pf8bit) then begin mak := 0; for br := 0 to form1.gb1.Width-1 do begin for kl := 0 to form1.gb1.Height-1 do begin dbaris := form1.gb1.Picture.Bitmap.ScanLine[br]; data := dbaris[kl]; h[data] := h[data] + 1; if (h[data]>mak) then mak := h[data]; end; end; end;

if (form1.gb1.Picture.Bitmap.PixelFormat = pf24bit) then begin makr := 0; makg := 0; makb := 0; for br := 0 to form1.gb1.height-1 do begin for kl := 0 to form1.gb1.width-1 do begin dbaris := form1.gb1.Picture.Bitmap.ScanLine[br]; data := dbaris[3*kl]; hb[data] := hb[data] + 1; if (hb[data]>makb) then makb := hb[data]; data := dbaris[3*kl+1]; hg[data] := hg[data] + 1; if (hg[data]>makg) then makg := hg[data]; data := dbaris[3*kl+2]; hr[data] := hr[data] + 1; if (hr[data]>makr) then makr := hr[data]; end; end; end;

if (form1.gb1.Picture.Bitmap.PixelFormat = pf8bit) then begin for lop := 0 to 255 do begin hasil := inttostr(lop) + ' = ' + inttostr(h[lop]); form1.memo1.Lines.Add(hasil); end; end;

if (form1.gb1.Picture.Bitmap.PixelFormat = pf8bit) then begin tinggi:=Form2.Image1.Height; for lop := 0 to 255 do begin form2.Image1.Canvas.Pen.Color:= clBlack; y1 := Round(h[lop]/mak*tinggi); y2 := Round(h[lop+1]/mak*tinggi); y1 := tinggi- y1 ; y2 := tinggi- y2; form2.Image1.Canvas.MoveTo(0+lop, y1); form2.Image1.Canvas.LineTo(1+lop, y2); end; end; if (form1.gb1.Picture.Bitmap.PixelFormat = pf24bit) then begin tinggi:=Form2.Image1.Height; for lop := 0 to 255 do begin form2.Image1.Canvas.Pen.Color := clRed; y1 := Round(hr[lop]/makr*tinggi); y2 := Round(hr[lop+1]/makr*tinggi); y1 := tinggi- y1 ; y2 := tinggi- y2; form2.Image1.Canvas.MoveTo(0+lop, y1); form2.Image1.Canvas.LineTo(1+lop, y2); form2.Image1.Canvas.Pen.Color := clGreen; y1 := Round(hg[lop]/makg*tinggi); y2 := Round(hg[lop+1]/makg*tinggi); y1 := tinggi- y1 ; y2 := tinggi- y2; form2.Image1.Canvas.MoveTo(0+lop, y1); form2.Image1.Canvas.LineTo(1+lop, y2); form2.Image1.Canvas.Pen.Color := clBlue; y1 := Round(hb[lop]/makb*tinggi); y2 := Round(hb[lop+1]/makb*tinggi); y1 := tinggi- y1 ; y2 := tinggi- y2; form2.Image1.Canvas.MoveTo(0+lop, y1); form2.Image1.Canvas.LineTo(1+lop, y2); end; end;

end;