Delphi图像细化处理


本文整理自网络,侵删。

 所谓细化,就是从原来的图中去掉一些点,但仍要保持原来的形状。实际上,是保持原图的骨架。

type
   TRGBArray = array[0..32767] of TRGBTriple;
   PRGBArray = ^TRGBArray;

procedure Xihua(Bitmap: TBitmap);
var
   bmp: TBitmap;
   X, Y: integer;
   O, T, C, B: pRGBArray;
   nb: array[1..3, 1..3] of integer;
   c1, c2, c3, c4: boolean;
   ncount: integer;
begin
   bmp := TBitmap.Create;
   bmp.Assign(bitmap);
   for Y := 1 to bmp.Height - 2 do
   begin
      O := bmp.ScanLine[Y];
      T := bitmap.ScanLine[Y - 1];
      C := bitmap.ScanLine[Y];
      B := bitmap.ScanLine[Y + 1];
      for X := 1 to bmp.Width - 2 do
      begin
         c1 := false;
         c2 := false;
         c3 := false;
         c4 := false;
         // 设立四个条件的初始值
         nb[1, 1] := T[X - 1].rgbtRed div 255;
         nb[1, 2] := T[X].rgbtRed div 255;
         nb[1, 3] := T[X + 1].rgbtRed div 255;
         nb[2, 1] := C[X - 1].rgbtRed div 255;
         nb[2, 2] := C[X].rgbtRed div 255;
         nb[2, 3] := C[X + 1].rgbtRed div 255;
         nb[3, 1] := B[X - 1].rgbtRed div 255;
         nb[3, 2] := B[X].rgbtRed div 255;
         nb[3, 3] := B[X + 1].rgbtRed div 255;
         //将[x,y]周围的八个象素点和它自己0-1化
         nCount := nb[1, 1] + nb[1, 2] + nb[1, 3] + nb[2, 1] + nb[2, 3] + nb[3, 1] + nb[3, 2] + nb[3, 3];
         // 获得ncount的值
         if (ncount >= 2) and (ncount <= 6) then c1 := True;
         //condition1
         ncount := 0;
         if (nb[1, 1] = 0) and (nb[1, 2] = 1) then inc(ncount);
         if (nb[1, 2] = 0) and (nb[1, 3] = 1) then inc(ncount);
         if (nb[1, 3] = 0) and (nb[2, 3] = 1) then inc(ncount);
         if (nb[2, 3] = 0) and (nb[3, 3] = 1) then inc(ncount);
         if (nb[3, 3] = 0) and (nb[3, 2] = 1) then inc(ncount);
         if (nb[3, 2] = 0) and (nb[3, 1] = 1) then inc(ncount);
         if (nb[3, 1] = 0) and (nb[2, 1] = 1) then inc(ncount);
         if (nb[2, 1] = 0) and (nb[1, 1] = 1) then inc(ncount);
         if ncount = 1 then c2 := true;
         //condition2
         if (nb[1, 2] * nb[3, 2] * nb[2, 3] = 0) then c3 := true;
         // condition3
         if (nb[2, 1] * nb[2, 3] * nb[3, 2] = 0) then c4 := true;
         //condition4
         if (c1 and c2 and c3 and c4) then
         begin
            O[X].rgbtRed := 255;
            O[X].rgbtGreen := 255;
            O[X].rgbtBlue := 255; //设置O[X]为白色
         end;
      end;
   end;
   bitmap.Assign(bmp);
   bmp.Free;
end;

相关阅读 >>

Delphi 如何设置热键

Delphi url 中文编解码

Delphi 获取鼠标坐标大全方法

Delphi 让子窗体显示在任务栏上

Delphi 如何编写使stringgrid中的一列具有check功能,和checkbox效果一样

Delphi的tservice 服务路径获取 dll中获取文件路径

Delphi inttostr 将“整数型”转换成“字符型”

Delphi 根据文件扩展名判断文件类型函数写法

Delphi 如何使用findfirst搜索不同的文件类型?

Delphi图片格式判断

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...