原理:
锐化就是增强图像的对比度,使亮处更亮,暗处更暗。因而可以使像素点的值大于125的乘以大于1的系数,而小于125的除以一个大于1的系数,从而达到亮处更亮,暗处更暗的效果。
实例:
var
Form18: TForm18;
Map1: TBitmap;
implementation
{$R *.dfm}
procedure TForm18.FormCreate(Sender: TObject);
begin
OpenDialog1.DefaultExt:=GraphicExtension(TBitmap);
OpenDialog1.Filter:=GraphicFilter(TBitmap);
if OpenDialog1.Execute then
begin
Map1:=TBitmap.Create;
Map1.LoadFromFile(OpenDialog1.FileName);
Image1.Picture.Bitmap:=Map1;
end;
end;
procedure TForm18.Button1Click(Sender: TObject);
var
xmax,ymax,i,j,m,n:integer;
r,g,b:integer;
temp:TColor;
begin
xmax:=Image1.Picture.Bitmap.Width-1;
ymax:=Image1.Picture.Bitmap.Height-1;
Label1.Caption:='锐化处理中...';
progressbar1.Min:=0;
progressbar1.Max:=xmax;
progressbar1.Position:=0;
progressbar1.Step:=1;
form18.Refresh;
for i:=1 to xmax do
begin
progressbar1.StepIt;
for j:=1 to ymax do
begin
if GetRValue(Image1.Canvas.Pixels[i,j])>125 then
r:=GetRValue(Image1.Canvas.Pixels[i,j])*8 div 7
else
r:=GetRValue(Image1.Canvas.Pixels[i,j])*7 div 8;
if GetGValue(Image1.Canvas.Pixels[i,j])>125 then
g:=GetGValue(Image1.Canvas.Pixels[i,j])*8 div 7
else
g:=GetGValue(Image1.Canvas.Pixels[i,j])*7 div 8;
if GetBValue(Image1.Canvas.Pixels[i,j])>125 then
b:=GetBValue(Image1.Canvas.Pixels[i,j])*8 div 7
else
b:=GetBValue(Image1.Canvas.Pixels[i,j])*7 div 8;
if r>255 then r:=255;
if g>255 then g:=255;
if b>255 then b:=255;
Image1.Canvas.Pixels[i,j]:=RGB(r,g,b);
end;
end;
Image1.Refresh;
Label1.Caption:='锐化处理完成...';
end;