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 禁用tedit右键菜单及复制粘贴

Delphi 调用批处理

Delphi 权限控制(Delphi tactionlist方案)

Delphi 获取当前输入法

Delphi 使richedit中的链接可以点击

Delphi 10.3 开发app 在android手机上获取imei

Delphi 获取鼠标当前位置的相对坐标

postmessage和sendmessage的区别

Delphi 端口扫描器原理

Delphi 切换开关 toggleswitch1

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



打赏

取消

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

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

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

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

评论

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