Doble klik button Exit, lalu ketik program berikut.
procedure TFormMorpologi.btMorpologiClickSender: TObject; var Mtrx:TMatrixFilter; nRow,nCol,r,c:integer;
begin Image2.Visible := True;
Image2.Picture.Graphic := Image1.Picture.Graphic; begin
nRow:=16; nCol:=16; nRow:=8; nCol:=8; coba coba
for c:=1 to nCol do for r:=1 to nRow do
Mtrx[r,c]:=1; ImgFilterMorphology Image2,Mtrx,nCol,nRow,2,ProgressBar1;
ImgFilterMorphology Image2,Mtrx,nCol,nRow,1,ProgressBar1; end;
end; procedure TFormMorpologi.btExitClickSender: TObject;
begin FormMorpologi.Close;
end; end.
unit UnitImageProses; interface
uses WINPROCS, Graphics, ExtCtrls, ComCtrls, Variants;
type TFreqHist = array [0..255] of longint;
TMatrixFilter = array [1..16,1..16] of real; function RgbToGray Clr:TColor : byte;
function ImgGetGray var Image:TImage; x,y:integer : byte; procedure
ImgConvertToGrayscale var
Image1:TImage; var
ProgressBar1: TProgressBar;
procedure ImgFilterMorphology
var Image:TImage;
Mtrx:TMatrixFilter; nCol,nRow,MaxMin:byte; var ProgressBar1: TProgressBar;
implementation const
PercentR = 0.299; PercentG = 0.587;
PercentB = 0.114; function ByteRange r:double : byte;
begin if r0 then ByteRange:=0
else if r255 then ByteRange:=255 else ByteRange:=Roundr;
end; function RgbToGray Clr:TColor : byte;
var r,g,b:byte; begin
r := GetRValueClr; g := GetGValueClr;
b := GetBValueClr; RgbToGray := ByteRange rPercentR + gPercentG + bPercentB;
end; function ImgGetGray var Image:TImage; x,y:integer : byte;
begin Result := RgbToGray Image.Canvas.Pixels[x,y];
end; procedure
ImgConvertToGrayscale var
Image1:TImage; var
ProgressBar1: TProgressBar;
var x,y:integer; ClrGray:byte; begin
ProgressBar1.Max := Image1.Width-1; ProgressBar1.Position := 0;
for x:=0 to Image1.Width-1 do begin
for y:=0 to Image1.Height-1 do begin
ClrGray := ImgGetGray Image1,x,y; Image1.Canvas.Pixels[x,y] := RGB ClrGray,ClrGray,ClrGray;
end; Image1.Repaint;
ProgressBar1.Position := x; end;
end; MaxMin=1 : dilasi+ MaxMin=2 : erosi-
procedure
ImgFilterMorphology var
Image:TImage; Mtrx:TMatrixFilter;
nCol,nRow,MaxMin:byte; var ProgressBar1: TProgressBar; var dx,dy:byte; ImgTemp:TImage;