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 将tbitmap与tgpimage转换

Delphi直接实现分享图片功能

Delphi 返回程序执行参数的例子

Delphi xe 获取android 系统版本

Delphi 分割文件合并文件的函数

Delphi android-api 开发常用函数

Delphi 获取按键键值

Delphi 10.2 ide界面

Delphi用命令行加载驱动

Delphi delete 删除字符串中指定的字符串

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



打赏

取消

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

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

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

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

评论

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