各位高手,小弟是菜鸟,刚接触DELPHI不久,跪求灰度图像锐化的代码,请大家帮忙啊。

解决方案 »

  1.   

    《Delphi数字图像处理及高级应用》
    http://ibook8.com/Software/Catalog17/10339.html
    附书源码
    http://www.tomore.com/down_file.php?id=33081
    里面有你想要的
      

  2.   

    Delphi数字图像处理及高级应用
      

  3.   

    24Bit锐化源码:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, ExtDlgs;type
      TForm1 = class(TForm)
        Button1: TButton;
        OpenPictureDialog1: TOpenPictureDialog;
        Button2: TButton;
        ScrollBox1: TScrollBox;
        ScrollBox2: TScrollBox;
        Image1: TImage;
        Image2: TImage;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    uses math;procedure TForm1.Button1Click(Sender: TObject);
    var
        bmp1, bmp2: Tbitmap;
        p1, p2, p3, p4: pbytearray;
        //定义四个pbytearray类型变量
        i, j, z: integer;
        y: array[0..8] of integer;
    begin
        y[0] := 0; y[1] := -1; y[2] := 0;
        y[3] := -1; y[4] := 5; y[5] := -1;
        y[6] := 0; y[5] := -1; y[8] := 0;
        //卷积矩阵
        z := 1;
        //卷积核
        bmp1 := Tbitmap.Create;
        bmp2 := Tbitmap.Create;
        bmp1.Assign(image1.Picture.Bitmap);
        bmp1.PixelFormat := pf24bit;
        //24为格式便于处理
        bmp1.Width := image1.Picture.Graphic.Width;
        bmp1.Height := image1.Picture.Graphic.Height;
        bmp2.Assign(bmp1);
        //备用的位图
        bmp2.PixelFormat := pf24bit;
        for j := 1 to bmp1.Height - 2 do
        begin
            p1 := bmp1.ScanLine[j];
            //第一条扫描线
            p2 := bmp2.ScanLine[j - 1];
            //第二条扫描线,为了防止数据变化,在备用位图上操作
            p3 := bmp2.ScanLine[j];
            p4 := bmp2.ScanLine[j + 1];
            //第三条扫描线
            //三条相邻的扫描线
            for i := 1 to bmp1.Width - 2 do
            begin
                //进行卷积操作获取新的象素值
                p1[3 * i + 2] := min(255, max(0, ((y[0] * p2[3 * (i - 1) + 2]
                    +
                    y[1] * p2[3 * i + 2] + y[2] * p2[3 * (i + 1) + 2] + y[3]
                    * p3[3
                    * (i - 1)
                        + 2] + y[4] * p3[3 * i + 2] + y[5] * p3[3 * (i + 1) +
                        2] +
                        y[6]
                    * p4[3
                    * (i - 1) + 2] + y[5] * p4[3 * i + 2] + y[8] * p4[3 * (i
                        +
                        1) + 2]))
                        div
                    z));
                //重新算出红色分量
                p1[3 * i + 1] := min(255, max(0, ((y[0] * p2[3 * (i - 1) + 1]
                    +
                    y[1] * p2[3 * i + 1] + y[2] * p2[3 * (i + 1) + 1] + y[3]
                    * p3[3
                    * (i - 1)
                        + 1] + y[4] * p3[3 * i + 1] + y[5] * p3[3 * (i + 1) +
                        1] +
                        y[6]
                    * p4[3
                    * (i - 1) + 1] + y[5] * p4[3 * i + 1] + y[8] * p4[3 * (i
                        +
                        1) + 1]))
                        div
                    z));
                //重新算出蓝色分量
                p1[3 * i] := min(255, max(0, ((y[0] * p2[3 * (i - 1)] + y[1]
                    *
                    p2[3 * i] + y[2] * p2[3 * (i + 1)] + y[3] * p3[3 * (i -
                        1)] +
                    y[4] * p3[3
                    * i] + y[5] * p3[3 * (i + 1)] + y[6] * p4[3 * (i - 1)] +
                        y[5]
                    * p4[3 * i]
                    + y[8] * p4[3 * (i + 1)])) div z));
                //重新算出绿色分量
            end;
        end;
        Image2.Picture.Bitmap.Assign(Bmp1);
        //重新显示
        Image2.Invalidate;
        Bmp1.Free;
        bmp2.Free;
        //释放资源
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
        Self.OpenPictureDialog1.Filter := '*.bmp|*.bmp';
        if OpenPictureDialog1.Execute then
        begin
            Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
        end;
    end;end.
      

  4.   

    图像的灰度转换
    procedure Gray(var bmp: TBitmap);
    var
      p: PByteArray;
      w: Integer;
      i, j: Integer;
    begin
      bmp.pixelformat := pf24bit;
      for i := 0 to bmp.height - 1 do
        begin
          p := bmp.scanline[i];
          j := 0;
          while j < (bmp.width - 1) * 3 do
            begin
              w := (p[j] * 28 + p[j + 1] * 151 + p[j + 2] * 77);
              w := w shr 8;
              p[j] := byte(w);
              p[j + 1] := byte(w);
              p[j + 2] := byte(w);
              inc(j, 3)
            end;
        end;
    end;
      

  5.   

    在学校学习<<图像处理>>的时候都做过...不过现在不记得了..
    现在看到了觉得有些熟悉...勾起大学的回忆