你是何希平吗? 我是谁你知道吗?
用中值滤波或者模板滤波试一下
//中值滤波:
procedure TFrmSmoothing.N4Click(Sender: TObject);
var
i,j , s, nTotal, nResult: integer;
ii, jj ,nTemp : integer;
m : array [1..30] of integer;
k : array [1..30] of integer;
begin
for i := 2 to Image1.Picture.Width-1 do
for j :=2 to Image1.Picture.Height-1 do
begin
m[1] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i-1,j-1]));
m[2] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j-1]));
m[3] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i+1,j-1]));
m[4] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i-1,j]));
m[5] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j]));
m[6] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i+1,j]));
m[7] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i-1,j+1]));
m[8] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i,j+1]));
m[9] := GetRValue(ColorToRGB(Image1.Canvas.Pixels[i+1,j+1]));
for ii:=1 to 8 do //冒泡排序
for jj :=ii to 8 do
begin
if m[jj] > m[jj+1] then
begin
nTemp :=m[jj];
m[jj] := m[jj+1];
m[jj+1] :=nTemp;
end;
end;
nResult := m[5];
Canvas.Pixels[i+320,j] := RGB(nResult,nResult,nResult);
end;
end;
//使用模板滤波
procedure TFrmSmoothing.N2Click(Sender: TObject);
var
i,j , s, nTotal, nResult: integer;
m : array [1..30] of integer;
k : array [1..30] of integer;
begin
k[1] := StrToInt(Edit1.text);
k[2] := StrToInt(Edit2.text);
k[3] := StrToInt(Edit3.text);
k[4] := StrToInt(Edit4.text);
k[5] := StrToInt(Edit5.text);
k[6] := StrToInt(Edit6.text);
k[7] := StrToInt(Edit7.text);
k[8] := StrToInt(Edit8.text);
k[9] := StrToInt(Edit9.text);
nTotal := 0;
for i:=1 to 9 do
nTotal := nTotal + k;
for i := 1 to min(328 ,Image1.Picture.Width) do
for j :=1 to min(328 ,Image1.Picture.Height) do
begin
m[1] := GetRValue(ColorToRGB(Canvas.Pixels[i-1,j-1]));
m[2] := GetRValue(ColorToRGB(Canvas.Pixels[i,j-1]));
m[3] := GetRValue(ColorToRGB(Canvas.Pixels[i+1,j-1]));
m[4] := GetRValue(ColorToRGB(Canvas.Pixels[i-1,j]));
m[5] := GetRValue(ColorToRGB(Canvas.Pixels[i,j]));
m[6] := GetRValue(ColorToRGB(Canvas.Pixels[i+1,j]));
m[7] := GetRValue(ColorToRGB(Canvas.Pixels[i-1,j+1]));
m[8] := GetRValue(ColorToRGB(Canvas.Pixels[i,j+1]));
m[9] := GetRValue(ColorToRGB(Canvas.Pixels[i+1,j+1]));
nResult := m[1]*k[1]+ m[2]*k[2]+ m[3]*k[3]+ m[4]*k[4]+ m[5]*k[5]+
m[6]*k[6]+ m[7]*k[7]+ m[8]*k[8]+ m[9]*k[9];
if nTotal<>0 then nResult := nResult div nTotal;
Canvas.Pixels[i+320,j] := RGB(nResult,nResult,nResult);
end;
end;