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从trichedit获得rtf格式文本

Delphi 通过 arp 协议获取局域网内指定 ip 地址的机器的 mac 地址

Delphi中inputbox 和inputquery 函数的使用

Delphi通过进程id获取主窗句柄

Delphi tms web core twebhttprequest使用

Delphi 突破主动防御

Delphi 显示windows断开网络驱动器对话框

Delphi 屏蔽汉字,年月日,时间,银行卡正则表达式

Delphi 的运算符重载

Delphi with do和for do语句

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



打赏

取消

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

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

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

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

评论

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