首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

图像细化解决办法

2012-03-20 
图像细化Delphi中有没有像C++中的图像细化的方法?[解决办法]《Delphi数字图像处理及高级应用》细化代码,必须

图像细化
Delphi   中有没有像C++中的图像细化的方法?

[解决办法]
《Delphi数字图像处理及高级应用》细化代码,必须在二值化基础上使用

function TMyPicture.Xihua(Bitmap: TBitmap): Boolean;
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;
// Create bmp
bmp.Assign(bitmap);
// 获取bitmap 赋给bmp
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;
//释放bmp
Result := True;
// 返回值为boolean,True表示细化成功
end;

procedure TMyPicture.Button8Click(Sender: TObject);
begin
if (XIhua(self.image1.Picture.Bitmap)) then
begin
image1.Picture.Bitmap.Assign(image1.Picture.Bitmap);
end
else
showmessage( '细化出错,请调试程序 ');
end;

[解决办法]
Visual Graph是一套强大的交互图形开发平台,她能非常方便地建造基于图形的界面、制作各种图形元件、实现图形管理、图形建模、制作监控系统、表单系统、绘图系统、流程设计、CAD软件等。她提供功能非常强大的ActiveX控件,和其他流行的编程语言共同工作,极大地弥补了这些语言在图形处理方面的不足。也可以嵌入IE浏览器中,实现网上图形编辑和控制等。http://www.visual-graph.com

热点排行