 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
li Guest
|
Posted: Fri Mar 25, 2005 6:59 am Post subject: how to thin a bitmap? |
|
|
Hi:
I write some code to thin a bitmap,but it can not work .Anybody can help
me!
Thanks !!
procedure TMyPicture.Button12Click(Sender: TObject);
var
bmp1, bmp2: Tbitmap;
// 临时位图
p1, p3, p2, p4: pByteArray;
i, j: integer;
r, g, b: Byte;
begin
self.DoubleBuffered := true;
//采用双缓冲模式
bmp1 := Tbitmap.Create;
bmp2 := Tbitmap.Create;
//Create bmp1,bmp2
bmp1.Assign(Image1.Picture.Bitmap);
bmp1.PixelFormat := pf24bit;
//设置位图格式
bmp2.Assign(bmp1);
bmp2.PixelFormat := pf24bit;
for j := 1 to bmp1.Height - 2 do
begin
p1 := bmp1.ScanLine[j];
p2 := bmp2.ScanLine[j - 1];
p3 := bmp2.ScanLine[j];
p4 := bmp2.ScanLine[j + 1];
for i := 1 to bmp1.Width - 2 do
begin
r := min(255, max(0, ((-p2[3 * (i - 1) + 2] - 2 * p2[3 * i +
2] -
p2[3 * (i
+
1) + 2] - 0 * p3[3 * (i - 1) + 2] + 0 * p3[3 * i + 2]
- 0 *
p3[3 * (i
+ 1)
+ 2] + p4[3 * (i - 1) + 2] + 2 * p4[3 * i + 2] + p4[3 * (i
+ 1)
+
2]))));
g := min(255, max(0, ((-p2[3 * (i - 1) + 1] - 2 * p2[3 * i +
1] -
p2[3 * (i
+
1) + 1] - 0 * p3[3 * (i - 1) + 1] + 0 * p3[3 * i + 1]
- 0 *
p3[3 * (i
+ 1)
+ 1] + p4[3 * (i - 1) + 1] + 2 * p4[3 * i + 1] + p4[3 * (i
+ 1)
+
1]))));
b := min(255, max(0, ((-p2[3 * (i - 1)] - 2 * p2[3 * i] - p2[3
*
(i + 1)]
- 0
* p3[3 * (i - 1)] + 0 * p3[3 * i] - 0 * p3[3 * (i + 1)] +
p4[3
* (i - 1)]
+ 2 * p4[3 * i + 2] + p4[3 * (i + 1)]))));
// 采用检测水平边缘的sobel算子[-1,-2,1,0,0,0,1,2,1]
p1[3 * i + 2] := min(255, max(0, ((-p2[3 * (i - 1) + 2] + 0 *
p2[3
* i + 2]
+
p2[3 * (i + 1) + 2] - 2 * p3[3 * (i - 1) + 2] + 0 * p3[3
* i +
2] + 2 *
p3[3 * (i
+ 1) + 2] - p4[3 * (i - 1) + 2] - 0 * p4[3 * i + 2] +
p4[3
* (i + 1) +
2]))));
p1[3 * i + 1] := min(255, max(0, ((-p2[3 * (i - 1) + 1] + 0 *
p2[3
* i + 1]
+
p2[3 * (i + 1) + 1] - 2 * p3[3 * (i - 1) + 1] + 0 * p3[3
* i +
1] + 2 *
p3[3 * (i
+ 1) + 1] - p4[3 * (i - 1) + 1] - 0 * p4[3 * i + 1] +
p4[3
* (i + 1) +
1]))));
p1[3 * i] := min(255, max(0, ((-p2[3 * (i - 1)] + 0 * p2[3 *
i] +
p2[3 * (i + 1)] - 2 * p3[3 * (i - 1)] + 0 * p3[3 * i] + 2
*
p3[3 * (i
+ 1)] - p4[3 * (i - 1)] - 0 * p4[3 * i] + p4[3 * (i +
1)]))));
//采用检测水平边缘的sobel算子[-1,0,1,-2,0,2,-1,0,1]
p1[3 * i + 2] := (max(r, p1[3 * i + 2]));
p1[3 * i + 1] := (max(g, p1[3 * i + 1]));
p1[3 * i] := (max(b, p1[3 * i]));
end;
end;
image1.Picture.Bitmap.Assign(bmp1);
// 读取已经利用sobel进行检测后的位图
bmp2.Free;
Bmp1.Free;
//释放资源
end;
|
|
| Back to top |
|
 |
li Guest
|
|
| Back to top |
|
 |
somebody Guest
|
Posted: Fri Mar 25, 2005 10:39 am Post subject: Re: how to thin a bitmap? |
|
|
"li" <li0713 (AT) hotmail (DOT) com> wrote
| Quote: | I write some code to thin a bitmap,but it can not work .Anybody can
help
me!
|
It may or may not help but if you need/could use vectorized results, one way
is edge detection followed by finding the medial axis. Google will get you
lots of stuff on those keywords.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|