Delphi提取二值图像轮廓


本文整理自网络,侵删。

 所谓轮廓提取就是掏空图形的内部点:如果原图中有一点为黑,且它的8个相邻点都是黑色时(此时该点是内部点),则将该点删除。

procedure GetFigure(Bitmap: TBitmap);
var
   b0, b1: Tbitmap;
   i, j: Integer;
   p1, p2, p3, p4: pbyteArray;
begin
   b0 := Tbitmap.Create;
   b1 := Tbitmap.Create;
   b0.Assign(Bitmap);
   b1.Assign(Bitmap);
   b0.PixelFormat := pf24bit;
   b1.PixelFormat := pf24bit;
   for i := 1 to b0.Height - 2 do
   begin
      //扫描三条三邻的像素行
      p1 := b0.ScanLine[i - 1];
      p2 := b0.ScanLine[i];
      p3 := b0.ScanLine[i + 1];
      p4 := b1.ScanLine[i];
      for j := 1 to b0.Width - 2 do
      begin
         if (p2[3 * j + 2] = 0) and (p2[3 * j + 1] = 0) and (p2[3 * j] = 0) then
         begin
            if ((p2[3 * (j - 1) + 2] = 0) and (p2[3 * (j - 1) + 1] = 0) and (p2[3 * (j - 1)] = 0)) and
               ((p2[3 * (j + 1) + 2] = 0) and (p2[3 * (j + 1) + 1] = 0) and (p2[3 * (j + 1)] = 0)) and
               ((p1[3 * (j + 1) + 2] = 0) and (p1[3 * (j + 1) + 1] = 0) and (p1[3 * (j + 1)] = 0)) and
               ((p1[3 * (j) + 2] = 0) and (p1[3 * (j) + 1] = 0) and (p1[3 * (j)]= 0)) and
               ((p1[3 * (j - 1) + 2] = 0) and (p1[3 * (j - 1) + 1] = 0) and (p1[3 * (j - 1)] = 0)) and
               ((p3[3 * (j - 1) + 2] = 0) and (p3[3 * (j - 1) + 1] = 0) and (p3[3 * (j - 1)] = 0)) and
               ((p3[3 * (j) + 2] = 0) and (p3[3 * (j) + 1] = 0) and (p3[3 * (j)]= 0)) and
               ((p3[3 * (j + 1) + 2] = 0) and (p3[3 * (j + 1) + 1] = 0) and (p3[3 * (j + 1)] = 0)) then
            begin
               p4[3 * j + 2] := 255;
               p4[3 * j + 1] := 255;
               p4[3 * j] := 255;
            end;
         end;
      end;
      Bitmap.Assign(b1);
   end;
   b1.Free;
   b0.Free;
end;

相关阅读 >>

Delphi 两字符串之间添加分隔符

Delphi paramstr的用法

Delphi richedit控件中插入图片bmp(bmp,文件),gif(文件)

在rad studio Delphi或c++安卓应用中使用自定义java库

Delphi ttabcontrol

Delphi waitforsingleobject 响应窗体

Delphi

Delphi 中的哈希表: thashedstringlist

Delphi使用api实现模拟按键

Delphi unigui 获取当前ip

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



打赏

取消

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

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

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

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

评论

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