BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to thin a bitmap?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
li
Guest





PostPosted: Fri Mar 25, 2005 6:59 am    Post subject: how to thin a bitmap? Reply with quote



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





PostPosted: Fri Mar 25, 2005 9:01 am    Post subject: Re: how to thin a bitmap? Reply with quote




"Avatar Zondertau" <avatarzt (AT) gmail (DOT) com> 写入消息新闻
:4243b891$1 (AT) newsgroups (DOT) borland.com...
Quote:
I write some code to thin a bitmap,but it can not work .Anybody
can help me!

If by "thinning" a bitmap you mean resizing it to a smaller size i
suggest that you take a look at the FastCode scale down challenge:

http://dennishomepage.gugs-cats.dk/ScaleDownChallenge.htm


No.I mean that a bitmap by thinning, some by thinning below:

http://www.21icsearch.com/buzi/upimage/upfile/20053251656040.jpg

http://www.21icsearch.com/buzi/upimage/upfile/20053251656480.jpg

thanks





Back to top
somebody
Guest





PostPosted: Fri Mar 25, 2005 10:39 am    Post subject: Re: how to thin a bitmap? Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.