本文主要是16位灰阶图的拉普拉斯算法做锐化:
unit Sharp;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ieview, imageenview, imageen,UImageUtils, ComCtrls,
Buttons;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ieview, imageenview, imageen,UImageUtils, ComCtrls,
Buttons;
type
TForm1 = class(TForm)
ImageEn1: TImageEn;
Button1: TButton;
dlgOpen1: TOpenDialog;
ImageEnView1: TImageEnView;
close: TButton;
Edit1: TEdit;
TrackBar1: TTrackBar;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
FImageBuffer: PWord;
FImageBuffer2: PWord;
FImageWidth, FImageHeight: Integer;
Lock: Boolean;
procedure sharpenImage(gray: PWord; smooth: PWord; width, height: Integer;n : Single);
procedure sharpenImagex(gray: PWord; smooth: PWord; width, height: Integer);
public
{ Public declarations }
end;
TForm1 = class(TForm)
ImageEn1: TImageEn;
Button1: TButton;
dlgOpen1: TOpenDialog;
ImageEnView1: TImageEnView;
close: TButton;
Edit1: TEdit;
TrackBar1: TTrackBar;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
FImageBuffer: PWord;
FImageBuffer2: PWord;
FImageWidth, FImageHeight: Integer;
Lock: Boolean;
procedure sharpenImage(gray: PWord; smooth: PWord; width, height: Integer;n : Single);
procedure sharpenImagex(gray: PWord; smooth: PWord; width, height: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
Form1: TForm1;
implementation
var
templates: array[0..24] of Integer =
(-1, -4, -7, -4, -1,
-4, -16, -26, -16, -4,
-7, -26, 505, -26, -7,
-4, -16, -26, -16, -4,
-1, -4, -7, -4, -1);
templates1: array[0..8] of Integer =
(0, -1, 0,
-1, 5, -1,
0, -1, 0);
templates: array[0..24] of Integer =
(-1, -4, -7, -4, -1,
-4, -16, -26, -16, -4,
-7, -26, 505, -26, -7,
-4, -16, -26, -16, -4,
-1, -4, -7, -4, -1);
templates1: array[0..8] of Integer =
(0, -1, 0,
-1, 5, -1,
0, -1, 0);
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
n : Single;c : Integer;
t: Cardinal;
begin
if not dlgOpen1.Execute then Exit;
ImageEn1.IO.LoadFromFile(dlgOpen1.FileName);
// ImageEnView1.IO.LoadFromFile(dlgOpen1.FileName);
Tiff16BitToBuffer(dlgOpen1.FileName, FImageBuffer, FImageWidth, FImageHeight);
var
n : Single;c : Integer;
t: Cardinal;
begin
if not dlgOpen1.Execute then Exit;
ImageEn1.IO.LoadFromFile(dlgOpen1.FileName);
// ImageEnView1.IO.LoadFromFile(dlgOpen1.FileName);
Tiff16BitToBuffer(dlgOpen1.FileName, FImageBuffer, FImageWidth, FImageHeight);
if Assigned(FImageBuffer2) then
FreeMem(FImageBuffer2);
GetMem(FImageBuffer2, FImageWidth * FImageHeight * SizeOf(Word));
Val(Edit1.Text,n,c);
t := GetTickCount;
sharpenImage(FImageBuffer, FImageBuffer2, FImageWidth, FImageHeight,0.95);
caption := IntToStr(GetTickCount - t);
BufferToTIFF16bit(FImageBuffer2, FImageWidth, FImageHeight,
dlgOpen1.FileName + '.123.tif');
ImageEnView1.IO.LoadFromFile(dlgOpen1.FileName + '.123.tif');
sharpenImage(FImageBuffer, FImageBuffer2, FImageWidth, FImageHeight,0.95);
caption := IntToStr(GetTickCount - t);
BufferToTIFF16bit(FImageBuffer2, FImageWidth, FImageHeight,
dlgOpen1.FileName + '.123.tif');
ImageEnView1.IO.LoadFromFile(dlgOpen1.FileName + '.123.tif');
end;
procedure TForm1.sharpenImage(gray, smooth: PWord; width, height: Integer;n : Single);
var
i,j: Integer;
index, sum: Integer;
grayPtr, smoothP
var
i,j: Integer;
index, sum: Integer;
grayPtr, smoothP